Experiencing FOMO on a perfect Bitcoin buying opportunity because you weren't glued to your screen 24/7? Or perhaps you've been on edge, constantly refreshing price charts, waiting for Bitcoin to hit that sweet buy-in point. Today, we're building a bot using BotFleet that monitors Bitcoin's price and sends you an email alert if it dips below a certain threshold.
The Plan
Our objective is simple yet powerful:
- Monitor Bitcoin's price in real-time.
- Send an email alert if the price drops below a predefined level.
Toolkit Checklist
Before we dive into coding, ensure you have:
- A BotFleet account, ready to deploy our crypto sentinel.
- Basic Python proficiency, to script our price-watching guardian.
- An API source for Bitcoin price data, like CoinGecko or CoinMarketCap.
- Access to an email service that allows sending emails programmatically.
The Script
We'll write a Python script that fetches Bitcoin's current price using a free API (CoinGecko in this example) and checks it against our target price. If the condition is met, it sends an email alert. Here's a starter script:
import os
import requests
from smtplib import SMTP
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# CoinGecko API for BTC price
btc_price_url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
# Target BTC price (USD)
target_price = 35000 # Change this to your desired alert level
# Email details
sender_email = "[email protected]"
receiver_email = "[email protected]"
password = os.environ.get("EMAIL_PASSWORD")
def check_btc_price():
response = requests.get(btc_price_url)
btc_price = response.json()['bitcoin']['usd']
if btc_price < target_price:
send_email_alert(btc_price)
def send_email_alert(btc_price):
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = receiver_email
message["Subject"] = "Bitcoin Price Alert!"
body = f"Hey there! Bitcoin has dropped below your target price of ${target_price}. Current price: ${btc_price}."
message.attach(MIMEText(body, "plain"))
with SMTP("smtp.example.com", 587) as server:
server.starttls()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, message.as_string())
print("Sent a Bitcoin price alert email.")
def main():
check_btc_price()
What's Happening Here?
Fetching BTC Price: We use the CoinGecko API to get the current price of Bitcoin in USD.
Checking Against Target: If Bitcoin's price falls below our set threshold, it triggers the email alert function.
Email Alert: A simple email is crafted and sent to notify us of the price drop.
Setting Up the Bot on BotFleet
Head over to BotFleet and go to the bots section. Name it something memorable, like "Bitcoin Price Alert Bot".
Indicating script
Copy the Python script we just wrote into the script section.
Indicating requirements
We're using the requests library. Let's add this to our requirements:
requests
Indicating environment variables
Set EMAIL_PASSWORD
as environment variable:
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 starting point. Feel free to enhance it by:
- Adding more cryptocurrencies to monitor.
- Integrating with more advanced email services for richer notifications.
- Setting up SMS or push notifications for instant alerts.
Wrapping Up
And just like that, you've got a personal Bitcoin price alert bot that works tirelessly so you don't have to. No more FOMO, no more constant chart-watching.
Got an idea to enhance this bot or a success story to share? Reach out.