DEV Community

Market Masters
Market Masters

Posted on

Build a Python Crypto Trading Bot: Real-Time RSI Alerts with CCXT

Build a Python Crypto Trading Bot: Real-Time RSI Alerts with CCXT

In 2026, AI handles most trades. But if you cannot code a basic alert bot, you do not understand the game. This 70-line Python script fetches live BTC/USDT prices from Binance via CCXT, computes RSI, and pings Telegram on oversold or overbought levels. No API keys needed to start.

Why Start Here?

RSI measures momentum. Below 30: potential buy. Above 70: potential sell. Simple rule to build intuition before complexity.

RSI misses trends, lags, and needs context. Pair it with volume or patterns later.

Prerequisites

pip install ccxt pandas-ta python-telegram-bot pandas
Enter fullscreen mode Exit fullscreen mode

Get a Telegram bot token: @botfather. Note your chat ID.

The Bot Code

Save as rsi_bot.py:

import ccxt
import pandas as pd
import pandas_ta as ta
import time
import requests

# Config - replace with yours
TELEGRAM_TOKEN = 'your_bot_token'
CHAT_ID = 'your_chat_id'
SYMBOL = 'BTC/USDT'
EXCHANGE_ID = 'binance'
TIMEFRAME = '1m'
RSI_PERIOD = 14
OVERSOLD = 30
OVERBOUGHT = 70

exchange = getattr(ccxt, EXCHANGE_ID)()

def send_alert(message):
    url = f'https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage'
    requests.post(url, json={'chat_id': CHAT_ID, 'text': message})

print('Bot started. Ctrl+C to stop.')
while True:
    try:
        ohlcv = exchange.fetch_ohlcv(SYMBOL, TIMEFRAME, limit=100)
        df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
        df['rsi'] = ta.rsi(df['close'], length=RSI_PERIOD)
        rsi = df['rsi'].iloc[-1]
        print(f'{pd.Timestamp.now()}: RSI {rsi:.2f}')

        if rsi < OVERSOLD:
            send_alert(f'🚨 {SYMBOL} RSI {rsi:.2f} - OVERSOLD (potential buy)')
        elif rsi > OVERBOUGHT:
            send_alert(f'🚨 {SYMBOL} RSI {rsi:.2f} - OVERBOUGHT (potential sell)')

        time.sleep(60)
    except Exception as e:
        print(f'Error: {e}')
        time.sleep(10)
Enter fullscreen mode Exit fullscreen mode

Run It

python rsi_bot.py
Enter fullscreen mode Exit fullscreen mode

Expect: Live RSI prints every minute. Alerts on extremes.

Tradeoffs

  • Public data only: No trades. Add API keys for orders.
  • Rate limits: Binance allows ~1200 req/min. Fine for 1m.
  • Polling: Switch to CCXT websocket for zero lag.
  • Single pair: Loop symbols[] for portfolio.

Test on testnet first. Paper trade before live.

Next Level: Market Masters AI

This bot gives signals. Market Masters adds AI pattern detection (triangles, wedges), Elliott Waves, conviction scores across 2500+ cryptos/stocks.

REST API ready: fetch patterns, setups in one call.

Start free at marketmasters.ai - no CC, 30-day Premium trial.

Build on this. Code wins.

Top comments (0)