DEV Community

Ray
Ray

Posted on

How I Use Alpaca's Free Paper Trading API to Test Strategies Without Risking Real Money

Paper trading is the best free education in algorithmic trading. No tuition. No real money at risk. Just you, your strategy, and real market data.

The catch: most paper trading setups are either too simple (a Python script that reads a CSV) or too complex (full cloud infrastructure before you've tested a single idea). There's a middle ground that works well — Alpaca's free paper trading API plus a local strategy runner.

Here's how I set it up with TradeSight, and what I learned.


Why Alpaca for Paper Trading

Alpaca gives you a free paper trading account with a fake $100,000 in capital. What makes it useful:

  • Real-time market data via WebSocket — prices update live, not T+15 min delayed
  • REST API for placing orders, checking positions, account balance
  • Realistic fills — market orders fill at current bid/ask, not the middle
  • Zero cost — the paper account is permanently free

The API is clean. Order placement looks like this:

import alpaca_trade_api as tradeapi

api = tradeapi.REST(
    key_id="YOUR_PAPER_KEY",
    secret_key="YOUR_PAPER_SECRET",
    base_url="https://paper-api.alpaca.markets"
)

# Buy 10 shares of AAPL at market
order = api.submit_order(
    symbol="AAPL",
    qty=10,
    side="buy",
    type="market",
    time_in_force="day"
)
print(order.id, order.status)
Enter fullscreen mode Exit fullscreen mode

Same code, same API — just a different base URL for paper vs live. That's the right abstraction.


The Problem With Just Testing It Live

The obvious approach: write a strategy, run it, see if it makes money.

The problem: you need a long time horizon to get statistically meaningful results from a single strategy run. 30 days of paper trading produces maybe 10-30 trades if you're selective. That's not enough to distinguish signal from noise.

What you actually want is parallel testing — multiple strategies running simultaneously, same capital, same universe of stocks, same time period. Then you can compare results and learn something.


Running Strategies in Parallel

TradeSight uses a tournament structure to solve this. Each strategy gets its own isolated paper trader instance:

from tradesight.paper_trader import PaperTrader
from tradesight.strategies import RSIMeanReversion, MACDCrossover, BollingerSqueeze

UNIVERSE = ["AAPL", "MSFT", "NVDA", "TSLA", "AMZN", "META", "GOOG", "JPM", "V", "ADBE"]
CAPITAL = 500.0  # Per strategy

traders = {
    "rsi":       PaperTrader(RSIMeanReversion(), capital=CAPITAL),
    "macd":      PaperTrader(MACDCrossover(), capital=CAPITAL),
    "bollinger": PaperTrader(BollingerSqueeze(), capital=CAPITAL),
}

# Each market day: evaluate signals for each strategy
def run_market_day():
    for symbol in UNIVERSE:
        data = fetch_daily_bars(symbol)
        for name, trader in traders.items():
            trader.evaluate(symbol, data)

# Log results
for name, trader in traders.items():
    stats = trader.get_stats()
    print(f"{name}: {stats['total_pnl']:+.2f} | {stats['win_rate']:.0%} win rate | {stats['trade_count']} trades")
Enter fullscreen mode Exit fullscreen mode

The key rule: no look-ahead bias. evaluate() only sees data up to the current simulation day. This is the most common mistake in backtesting — peeking at future prices during strategy evaluation makes everything look better than it is.


What Actually Gets Tracked

For each strategy, TradeSight tracks:

  • P&L per trade — not just total, but per-trade distribution
  • Win rate — weighted by trade count (3 trades with 67% win rate is noise)
  • Max drawdown — how far did the strategy fall from its peak?
  • Market regime context — was this a trending or range-bound period?

That last one matters more than most people realize. RSI mean reversion crushes it in sideways markets. It gets destroyed in trends. If you test during a trending month and RSI looks bad, you might throw away a good strategy for the wrong reason.


The Overnight Runner

The part that made this actually useful: a cron job that runs the tournament every night after market close.

#!/usr/bin/env python3
# overnight_runner.py — runs via cron at 6 PM weekdays

from tradesight.tournament import TournamentRunner

UNIVERSE = ["AAPL", "MSFT", "NVDA", "TSLA", "AMZN", "META", "GOOG"]

runner = TournamentRunner(
    strategies=["rsi", "macd", "bollinger", "confluence"],
    universe=UNIVERSE,
    capital_per_strategy=500.0
)

# Run today's simulation
results = runner.run_day()

# Log to dashboard
runner.log_results(results)

# Prune strategies with 30-day negative P&L
runner.prune_losers(threshold=-100.0)
Enter fullscreen mode Exit fullscreen mode

Wake up, check the dashboard, see which strategies are up and which are down. Adjust. Repeat.

The compounding effect over weeks is real — you accumulate data about how your strategies perform across different market conditions, not just "it looked good in backtesting."


The Honest Limitations

Paper trading isn't real trading. You'll miss slippage on large orders, psychological pressure, and market impact. Paper fills at market price; real fills are worse.

30 days isn't enough. For any strategy with fewer than 50 trades, the win rate is statistically meaningless. Paper trade for 6-12 months before drawing conclusions.

Survivorship bias. If you prune bad strategies and keep good ones, you end up with "the strategies that did well in this specific market period." That's not the same as strategies that work in general.


Getting Started

  1. Create a free Alpaca paper account — 2 minutes, no identity verification needed for paper
  2. Grab your paper API keys from the Alpaca dashboard
  3. Clone TradeSight:
  4. Add your keys to
  5. Run — dashboard opens at localhost:5000

No cloud setup. No subscriptions. Runs entirely on your machine.


The best thing about paper trading isn't learning whether your strategy works. It's learning why — what market conditions it's built for, what regimes break it. That understanding is what carries over when you eventually run it with real money.

TradeSight on GitHub — MIT licensed, self-hosted, paper trading from day one.

Top comments (0)