Skip to main content

Building a Crypto Signal Alert Bot with BotFleet - Monitoring Twitter with Ease

· 4 min read
Bakar Tavadze

Building a Crypto Signal Alert Bot with BotFleet: Monitoring Twitter with Ease

Greetings crypto enthusiasts and Twitter users! Ever find yourself glued to certain Twitter accounts waiting for those valuable crypto signals? You know, those tweets that hint at the next big move in the crypto market. Welcome to today's project: crafting a bot with BotFleet that monitors Twitter for specific crypto signals and sends you an email alert the moment it detects one. Let's jump in!

The Blueprint

Our goal is to create a bot that does the following:

  1. Monitors a specific Twitter account for new tweets.
  2. Searches those tweets for predefined crypto signal keywords.
  3. Sends an email alert when it finds a match.
  4. Sounds like a plan? Perfect, let's get our tools ready.

Gear Up for the Mission

Before we embark on this coding adventure, make sure you have:

  1. A BotFleet account, ready to deploy our bot.
  2. Basic Python knowledge, to script our digital lookout.
  3. Access to the Twitter API, for fetching tweets.
  4. An email service that allows sending emails via API or SMTP.

The Script

Our Python script will use the Twitter API to fetch recent tweets from a specified account, search for our crypto signal keywords, and if found, send us an email alert. Here's a simplified version to get us started:

import os
import tweepy
from smtplib import SMTP
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

# Twitter API credentials
consumer_key = os.environ['TWITTER_CONSUMER_KEY']
consumer_secret = os.environ['TWITTER_CONSUMER_SECRET']
access_token = os.environ['TWITTER_ACCESS_TOKEN']
access_token_secret = os.environ['TWITTER_ACCESS_TOKEN_SECRET']

# Email setup
sender_email = "[email protected]"
receiver_email = "[email protected]"
email_password = os.environ['EMAIL_PASSWORD']

# The Twitter account and keywords to monitor
twitter_account = 'crypto_signals'
keywords = ['buy signal', 'sell signal']

def check_for_signals():
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

# Fetching the most recent tweets from the account
tweets = api.user_timeline(screen_name=twitter_account, count=10, tweet_mode='extended')
for tweet in tweets:
if any(keyword in tweet.full_text.lower() for keyword in keywords):
send_email_alert(tweet.full_text)

def send_email_alert(tweet):
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = "New Crypto Signal Detected!"

body = f"Hey there! A new crypto signal was detected on Twitter: \n\n{tweet}"
message.attach(MIMEText(body, "plain"))

with SMTP("smtp.example.com", 587) as server:
server.starttls()
server.login(sender_email, email_password)
server.sendmail(sender_email, receiver_email, message.as_string())
print("Sent an email alert about a new crypto signal.")

def main():
check_for_signals()

What's Happening Here?

Tweepy for Twitter: We're using the Tweepy library to authenticate with Twitter's API and fetch recent tweets from a specified account.

Detecting Crypto Signals: The script scans each tweet for our list of crypto-related keywords.

Email Alerts: When a keyword is detected, it crafts and sends an email to alert you of the potential signal.

Setting Up the Bot on BotFleet

Head over to BotFleet and go to the bots section. Name it something memorable, like "Crypto Signal Alert Bot.".

Indicating script

Copy the Python script we just wrote into the script section.

Indicating requirements

We're using the tweepy library. Let's add this to our requirements:

tweepy

Indicating environment variables

Set TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET, and EMAIL_PASSWORD as environment variables:

TWITTER_CONSUMER_KEY=your-consumer-key
TWITTER_CONSUMER_SECRET=your-consumer-secret
TWITTER_ACCESS_TOKEN=your-access-token
TWITTER_ACCESS_TOKEN_SECRET=your-access-token-secret
EMAIL_PASSWORD=your-email-password

Schedule It

Set your bot to run every minute. You can use the following cron expression to run your bot every minute:

* * * * *

Beyond the Basics

This script is your foundation. You can customize it further by:

  1. Adding more sophisticated text analysis to better identify genuine signals.
  2. Monitoring multiple accounts or keywords.
  3. Integrating with more advanced email templates or services for richer alerts.

Wrapping Up

And there you have it—a personalized crypto signal alert system that keeps you in the loop without chaining you to Twitter. Now, you can focus more on strategy and less on constant monitoring.

Got an upgrade idea for this bot or a success story to share? Reach out.