📅 April 2, 2026 python alpaca-api paper-trading algorithmic-trading

Building a Paper Trading Bot with Python + Alpaca API

Paper trading is one of the best ways to validate a strategy without risking real capital. The problem: most setups are either too manual (spreadsheets) or too heavyweight (commercial platforms with lock-in). This post walks through TradeSight - a lightweight, open-source Python bot that runs 4 concurrent strategies against Alpaca's paper trading API.

Live results as of April 2, 2026: +6.43% portfolio return over ~32 trades. MACD Crossover leading (+.89 on JPM). RSI struggling (-.77 net). VIX at 25.4 - high volatility regime.

Why Alpaca?

Alpaca gives you a free paper trading API that mirrors real market conditions - real prices, realistic fills, market hours enforcement. No signup fee, no monthly cost. Their Python SDK (alpaca-py) handles authentication, order submission, and position tracking cleanly.

pip install alpaca-py pandas numpy

Architecture

TradeSight runs 4 strategies in parallel, each managing its own position slice:

Core MACD Implementation

import pandas as pd
from alpaca.data.historical import StockHistoricalDataClient
from alpaca.data.requests import StockBarsRequest
from alpaca.data.timeframe import TimeFrame

def get_macd_signal(symbol, api_key, secret_key):
    client = StockHistoricalDataClient(api_key, secret_key)
    request = StockBarsRequest(
        symbol_or_symbols=symbol,
        timeframe=TimeFrame.Hour,
        limit=100
    )
    bars = client.get_stock_bars(request).df
    close = bars["close"]
    ema_fast = close.ewm(span=12, adjust=False).mean()
    ema_slow = close.ewm(span=26, adjust=False).mean()
    macd = ema_fast - ema_slow
    signal = macd.ewm(span=9, adjust=False).mean()
    if macd.iloc[-1] > signal.iloc[-1] and macd.iloc[-2] <= signal.iloc[-2]:
        return "BUY"
    elif macd.iloc[-1] < signal.iloc[-1] and macd.iloc[-2] >= signal.iloc[-2]:
        return "SELL"
    return "HOLD"

Live Results Breakdown

StrategyNet P&LTop TradeNotes
MACD Crossover+.89JPM +.12Strong in trending regime
RSI Mean Reversion-.77-High VIX kills mean reversion
VWAP Reversion-/bin/bash.75-0% win rate this period
Bollinger Breakout+.44NVDA +.90More breakouts in volatile market

In a high-VIX environment, momentum strategies outperform mean-reversion plays. Mean reversion assumes prices return to equilibrium - that breaks down in volatile regimes.

Running It Yourself

git clone https://github.com/rmbell09-lang/tradesight
cd tradesight
cp .env.example .env
# Add Alpaca paper trading API key + secret
pip install -r requirements.txt
python paper_trader.py

Free and open source

TradeSight is MIT-licensed. Fork it, modify it, run your own strategies. github.com/rmbell09-lang/tradesight

What is Next

Regime detection is the obvious next step - automatically weighting strategies based on market conditions. When VIX exceeds 20, reduce RSI allocation and increase MACD weight. Also planning WebSocket reconnect logic and a 7-day ticker cooldown after stop-losses.

Building something similar? Open an issue or star the repo.