Build a Real-Time Crypto Trading Bot in Python: Live Prices, RSI Signals, and Telegram Alerts
Crypto prices update every second. Retail traders need tools that spot overbought signals before the crowd. This tutorial builds a Python bot that pulls live Binance prices via CCXT, calculates RSI with TA-Lib, and sends Telegram alerts when RSI hits extremes.
No fluff. You get a working script in 30 minutes. Deploy it on a VPS for 24/7 monitoring.
Why RSI for Trading?
RSI measures momentum on a 0-100 scale. Above 70: overbought, sell signal. Below 30: oversold, buy signal. False signals happen in trends, so pair it with price action.
This bot checks BTC/USDT every minute. Alerts fire on crossovers.
Prerequisites
- Python 3.10+
- Binance account (read-only API key optional for public data)
- Telegram bot token (create via @botfather)
Install libraries:
pip install ccxt pandas TA-Lib telebot
TA-Lib needs binary install. On Ubuntu:
sudo apt update
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install
pip install TA-Lib
Step 1: Fetch Real-Time Prices
CCXT unifies 100+ exchanges. Public data needs no API key.
import ccxt
import pandas as pd
from datetime import datetime
exchange = ccxt.binance()
symbol = 'BTC/USDT'
def fetch_ohlcv():
ohlcv = exchange.fetch_ohlcv(symbol, timeframe='1m', limit=100)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
return df
fetch_ohlcv grabs 100 candles. Each row: open, high, low, close, volume.
Step 2: Calculate RSI
TA-Lib handles indicators. RSI(14) is standard.
import talib
def calculate_rsi(df, period=14):
df['rsi'] = talib.RSI(df['close'], timeperiod=period)
return df
NaN on first 14 periods. Ignore them.
Step 3: Send Telegram Alerts
Create a bot, get token and chat_id.
import telebot
TELEGRAM_TOKEN = 'your_bot_token'
CHAT_ID = 'your_chat_id'
bot = telebot.TeleBot(TELEGRAM_TOKEN)
def send_alert(message):
bot.send_message(CHAT_ID, message)
Step 4: Trading Logic
Buy if RSI < 30 and rising. Sell if RSI > 70 and falling.
def check_signals(df):
latest_rsi = df['rsi'].iloc[-1]
prev_rsi = df['rsi'].iloc[-2]
if latest_rsi < 30 and latest_rsi > prev_rsi:
send_alert(f"π BTC/USDT OVERSOLD: RSI {latest_rsi:.1f} (rising from {prev_rsi:.1f}) at {datetime.now()}")
elif latest_rsi > 70 and latest_rsi < prev_rsi:
send_alert(f"π΄ BTC/USDT OVERBOUGHT: RSI {latest_rsi:.1f} (falling from {prev_rsi:.1f}) at {datetime.now()}")
Full Bot Script
Combine it. Runs forever, sleeps 60s.
import time
import ccxt
import pandas as pd
import talib
import telebot
from datetime import datetime
# Config
TELEGRAM_TOKEN = 'your_bot_token_here'
CHAT_ID = 'your_chat_id_here'
SYMBOL = 'BTC/USDT'
exchange = ccxt.binance()
bot = telebot.TeleBot(TELEGRAM_TOKEN)
def fetch_data():
ohlcv = exchange.fetch_ohlcv(SYMBOL, '1m', 100)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
df['rsi'] = talib.RSI(df['close'])
return df
def send_alert(message):
try:
bot.send_message(CHAT_ID, message)
except:
print("Alert failed")
while True:
try:
df = fetch_data()
latest_rsi = df['rsi'].dropna().iloc[-1]
prev_rsi = df['rsi'].dropna().iloc[-2]
price = df['close'].iloc[-1]
if latest_rsi < 30 and latest_rsi > prev_rsi:
send_alert(f"π BUY SIGNAL {SYMBOL}: RSI {latest_rsi:.1f}β Price ${price:,.0f}")
elif latest_rsi > 70 and latest_rsi < prev_rsi:
send_alert(f"π΄ SELL SIGNAL {SYMBOL}: RSI {latest_rsi:.1f}β Price ${price:,.0f}")
print(f"Checked at {datetime.now()}: RSI {latest_rsi:.1f}, Price ${price:,.0f}")
except Exception as e:
print(f"Error: {e}")
time.sleep(60)
Test and Deploy
Run locally: python bot.py
Expect output like: "Checked at 2026-05-05 08:30: RSI 45.2, Price $95,420"
Deploy: VPS with screen or systemd. Use python -u bot.py > bot.log 2>&1 &
Add MACD or volume filter to reduce noise.
Next Level
This bot scratches the surface. For 2,500+ coins, chart patterns, AI setups, and paper trading: check Market Masters AI. Free tier screens signals across Binance/Bybit stocks. Start your 30-day Premium trial: https://marketmasters.ai
Build, test, trade smarter.
Top comments (0)