DEV Community

Market Masters
Market Masters

Posted on

Build a Python Trading Bot: Real-Time RSI Alerts with Market Masters API

Build a Python Trading Bot: Real-Time RSI Alerts with Market Masters API

Retail traders lose edges because signals arrive too late. Market Masters API fixes that. It pulls live prices from 2,500+ cryptos and S&P 500 stocks into your code. This tutorial builds a lean Python bot that computes RSI, spots oversold buys, and pings Telegram. Runs in 50 lines. No Docker, no Kubernetes.

Why Market Masters API

Most APIs charge per call or lock data behind $500/month subs. Market Masters starts free: screeners, Orion AI, and REST endpoints for prices, TA scores, order flow. Get your key at marketmasters.ai (free tier, no card).

Tradeoffs: Free tier limits 100 calls/minute. Paid unlocks unlimited + WebSockets. Docs cover endpoints like /v1/prices/{symbol} (BTCUSDT, AAPL).

Setup

pip install requests pandas ta-lib pandas-ta
Enter fullscreen mode Exit fullscreen mode

Get API key from dashboard. Store in .env:

MM_API_KEY=your_key_here
TELEGRAM_TOKEN=bot_token
TELEGRAM_CHAT_ID=your_chat_id
Enter fullscreen mode Exit fullscreen mode

Core loop: Fetch, analyze, alert

import os
import time
import requests
import pandas as pd
import numpy as np
import telegram
from dotenv import load_dotenv
import talib

load_dotenv()

MM_BASE = "https://api.marketmasters.ai/v1"
API_KEY = os.getenv("MM_API_KEY")
TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")

bot = telegram.Bot(token=TELEGRAM_TOKEN)

def get_prices(symbol, interval="1m", limit=100):
    url = f"{MM_BASE}/prices/{symbol}?interval={interval}&limit={limit}"
    headers = {"Authorization": f"Bearer {API_KEY}"}
    resp = requests.get(url, headers=headers)
    if resp.status_code != 200:
        raise ValueError(f"API error: {resp.text}")
    data = resp.json()["prices"]
    df = pd.DataFrame(data)
    df["timestamp"] = pd.to_datetime(df["timestamp"])
    df.set_index("timestamp", inplace=True)
    return df

def rsi_alert(df, symbol, period=14, oversold=30, overbought=70):
    rsi = talib.RSI(df["close"].values, timeperiod=period)
    latest_rsi = rsi[-1]
    prev_rsi = rsi[-2]

    if latest_rsi < oversold and prev_rsi >= oversold:
        msg = f"{symbol} oversold! RSI {latest_rsi:.1f} (from {prev_rsi:.1f}). Price: ${df[\"close\"].iloc[-1]:.4f}"
        bot.send_message(chat_id=CHAT_ID, text=msg)
    elif latest_rsi > overbought and prev_rsi <= overbought:
        msg = f"{symbol} overbought! RSI {latest_rsi:.1f} (from {prev_rsi:.1f}). Price: ${df[\"close\"].iloc[-1]:.4f}"
        bot.send_message(chat_id=CHAT_ID, text=msg)

symbols = ["BTCUSDT", "ETHUSDT", "AAPL"]
while True:
    for sym in symbols:
        try:
            df = get_prices(sym)
            rsi_alert(df, sym)
        except Exception as e:
            print(f"Error {sym}: {e}")
    time.sleep(60)
Enter fullscreen mode Exit fullscreen mode

Gotchas I hit

  • TA-Lib install: Ubuntu/Debian: sudo apt install ta-lib. macOS: brew install ta-lib. Windows: wheels via conda.
  • Rate limits: Free tier 100/min. Batch symbols in one call if API supports /prices/multi.
  • Data format: Test endpoint first. Market Masters returns timestamp, open, high, low, close, volume.
  • Async for scale: Swap requests for aiohttp + asyncio.gather on 100 symbols.
  • Backtesting: Use historical /prices?start=2026-01-01 to validate signals.

Run it

python bot.py
Enter fullscreen mode Exit fullscreen mode

Deploy: nohup python bot.py & on VPS. Monitor logs. Add risk mgmt: position sizing, stop-loss via API orders if integrated.

Market Masters covers futures/ETFs too. Free tier gets you started.

Start building: marketmasters.ai free trial.

Top comments (0)