Build a Trading Bot with the MarketMasters API in Python
Learn how to automate your trading decisions with real-time market data and technical indicators.
Why Build a Trading Bot?
Trading is emotional. A bot isn't. By automating your strategy, you:
- Remove emotion from entries and exits
- Execute trades instantly when conditions are met
- Monitor multiple markets 24/7
- Backtest strategies with historical data
In this guide, we'll build a simple trading bot using the MarketMasters API — which gives you institutional-grade data including klines, chart patterns, Elliott Wave analysis, and more.
Prerequisites
pip install requests pandas
You'll need a MarketMasters API key from marketmasters.ai/profile/account.
Step 1: Set Up the API Client
import requests
BASE_URL = "https://api.marketmasters.ai/v1"
API_KEY = "your_api_key_here"
headers = {
"x-api-key": API_KEY
}
def get_klines(symbol, timeframe="1h", limit=50):
url = f"{BASE_URL}/klines"
params = {"symbol": symbol, "timeframe": timeframe, "limit": limit}
response = requests.get(url, headers=headers, params=params)
return response.json()
The API returns klines with embedded indicators: RSI(14), ADX(14), DMI+/-, ROC(9), and volume metrics.
Step 2: Analyze the Data
def analyze_signal(klines):
latest = klines[-1]
rsi = latest[8] # RSI(14)
adx = latest[9] # ADX(14)
dmi_plus = latest[10]
dmi_minus = latest[11]
if rsi < 30 and adx > 20 and dmi_plus > dmi_minus:
return "BUY"
elif rsi > 70 and adx > 20 and dmi_minus > dmi_plus:
return "SELL"
return "HOLD"
btc_data = get_klines("BTCUSDT", "1h", 20)
print(f"Signal: {analyze_signal(btc_data)}")
Step 3: Chart Patterns
def get_active_patterns(symbols="BTCUSDT,ETHUSDT,SOLUSDT"):
url = f"{BASE_URL}/chartpatterns"
params = {"symbols": symbols}
return requests.get(url, headers=headers, params=params).json()
patterns = get_active_patterns()
for pattern in patterns:
if pattern.get("score", 0) > 80:
print(f"{pattern['symbol']}: {pattern['type']}")
Step 4: Elliott Wave
def get_elliott_wave(symbol, tf="4h"):
url = f"{BASE_URL}/elliottwave"
return requests.get(url, headers=headers, params={"symbols": symbol, "timeframe": tf}).json()
Step 5: Trading Loop
import time
def trading_loop():
symbols = ["BTCUSDT", "ETHUSDT", "SOLUSDT"]
while True:
for symbol in symbols:
klines = get_klines(symbol, "1h", 20)
print(f"{symbol}: {analyze_signal(klines)}")
time.sleep(3600)
API Endpoints
| Endpoint | Use Case |
|---|---|
| /klines | OHLCV + RSI, ADX |
| /chartpatterns | Auto patterns |
| /elliottwave | Wave analysis |
| /stocks/klines | Stock data |
| /stocks/analysis | Fundamentals |
Notes
- Free tier = 30 req/min
- Backtest before live trading
- Use stop losses
- Paper trade first
Get your API key at marketmasters.ai
Happy trading!
Top comments (0)