How to Set Up a Free Crypto Price Alert System in Python
Build a crypto price alert system that sends Telegram notifications when your target price is hit. Free, runs 24/7, and takes 15 minutes to set up.
Builder of AI agents, crypto trading bots, and open-source automation tools. Sharing practical guides on how to build, deploy, and profit from AI and DeFi technology.
A price alert is the simplest useful crypto automation you can build. This tutorial builds one that monitors any coin and sends you a Telegram message when price crosses your target. Free and runs 24/7.
What You'll Build
- Python script that checks price every 60 seconds
- Telegram bot that sends you alerts
- Multiple alerts (above/below targets)
- Free: uses CoinGecko API (no API key required)
Step 1: Create a Telegram Bot
- Open Telegram, search for @BotFather
- Send
/newbot - Give your bot a name and username
- Copy the HTTP API token (looks like
1234567890:ABCdefGHI...) - Start a chat with your new bot (so it can message you)
- Find your chat ID: Go to
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdatesand look for"chat":{"id": XXXXXXXXX}
pip install requests python-dotenv
Create .env:
TELEGRAM_TOKEN=your_token_here
TELEGRAM_CHAT_ID=your_chat_id_here
Step 2: The Alert System
import requests
import time
import os
from dataclasses import dataclass
from typing import Optional
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("TELEGRAM_TOKEN")
CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")
@dataclass
class Alert:
coin_id: str # CoinGecko ID: 'bitcoin', 'ethereum', 'solana'
symbol: str # Display: 'BTC'
target_price: float
direction: str # 'above' or 'below'
triggered: bool = False
message: Optional[str] = None
def send_telegram(message: str):
"""Send a Telegram message."""
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
requests.post(url, json={"chat_id": CHAT_ID, "text": message, "parse_mode": "HTML"})
def get_prices(coin_ids: list[str]) -> dict[str, float]:
"""Get current prices from CoinGecko (free, no API key)."""
ids = ",".join(coin_ids)
url = f"https://api.coingecko.com/api/v3/simple/price?ids={ids}&vs_currencies=usd"
r = requests.get(url, timeout=10)
data = r.json()
return {coin: data[coin]['usd'] for coin in coin_ids if coin in data}
def check_alerts(alerts: list[Alert], prices: dict[str, float]) -> list[Alert]:
"""Check all alerts and trigger if conditions met."""
triggered = []
for alert in alerts:
if alert.triggered:
continue
price = prices.get(alert.coin_id)
if price is None:
continue
should_trigger = (
(alert.direction == 'above' and price >= alert.target_price) or
(alert.direction == 'below' and price <= alert.target_price)
)
if should_trigger:
alert.triggered = True
triggered.append(alert)
direction_emoji = "๐" if alert.direction == 'above' else "๐ด"
message = (
f"{direction_emoji} <b>Price Alert: {alert.symbol}</b>\n"
f"Target: ${alert.target_price:,}\n"
f"Current: ${price:,.2f}\n"
f"Direction: {alert.direction.upper()}"
)
if alert.message:
message += f"\nNote: {alert.message}"
send_telegram(message)
print(f"โ
Alert triggered: {alert.symbol} {alert.direction} ${alert.target_price:,}")
return triggered
def run_alerts(alerts: list[Alert], interval: int = 60):
"""Main monitoring loop."""
active = [a for a in alerts if not a.triggered]
coin_ids = list(set(a.coin_id for a in active))
print(f"๐ Monitoring {len(active)} alerts for {', '.join(coin_ids)}")
send_telegram(f"โ
Price alert system started\nMonitoring: {', '.join(coin_ids)}")
while active:
try:
prices = get_prices(coin_ids)
# Show current prices
price_str = " | ".join(f"{a.symbol}: ${prices.get(a.coin_id, 0):,.0f}"
for a in active if not a.triggered)
print(f"\r{price_str}", end="", flush=True)
newly_triggered = check_alerts(active, prices)
active = [a for a in active if not a.triggered]
if not active:
print("\n\nAll alerts triggered! Exiting.")
send_telegram("๐ฏ All price alerts have been triggered!")
break
time.sleep(interval)
except requests.RequestException as e:
print(f"\nNetwork error: {e}. Retrying in 60s...")
time.sleep(60)
except KeyboardInterrupt:
print("\n\nMonitoring stopped.")
break
# Define your alerts
alerts = [
Alert('bitcoin', 'BTC', 70000, 'above', message="ATH breakout!"),
Alert('bitcoin', 'BTC', 55000, 'below', message="Consider buying the dip"),
Alert('ethereum', 'ETH', 4000, 'above'),
Alert('ethereum', 'ETH', 2500, 'below'),
Alert('solana', 'SOL', 200, 'above'),
]
run_alerts(alerts, interval=60)
Running It 24/7 Free
Option 1: Always-on laptop/desktop
nohup python alerts.py > alerts.log 2>&1 &
Option 2: Free cloud (Replit)
- Create a free account at replit.com
- New Python repl โ paste your code
- Add environment variables in Secrets
- Enable "Always On" (requires basic plan ~$7/month)
Option 3: GitHub Actions (completely free)
Create .github/workflows/price-check.yml:
name: Price Alerts
on:
schedule:
- cron: '*/5 * * * *' # Every 5 minutes
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with: { python-version: '3.12' }
- run: pip install requests
- run: python check_alerts.py
env:
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
This runs every 5 minutes for free on GitHub's servers.
Extend It
- Add portfolio value alerts ("notify me when my portfolio drops 10%")
- Add RSI/technical indicator alerts
- Connect to our trading bot guide to auto-trade when alerts trigger
A simple alert system like this is the foundation for more complex automation.
Related Articles
How to Write a Python Script That Trades Crypto Automatically
7 min read
Crypto BotsHow to Use the Binance API: Complete Beginner Guide (2025)
8 min read
Crypto BotsPython for Crypto: The Complete Developer's Toolkit (2025)
5 min read
Crypto BotsThe Complete Guide to Crypto Trading Bot Strategies (2025)
9 min read