Test your trading strategy on past markets to validate before going live.
As @the_smart_ape discovered, Polymarket's historical API is incomplete for many markets. We have several workarounds:
- Pros: Complete OHLCV data, reliable
- Cons: Paid service ($)
- Setup: Get API key from https://adjacent.finance
export ADJACENT_API_KEY="your_key_here"- Pros: Free, official
- Cons: Often returns empty data
- Works for: Recent, high-volume markets only
- Pros: Accurate, custom
- Cons: Need to record for weeks/months first
- Setup: Run paper trader to start recording
- Pros: Can control scenario
- Cons: Limited scope
python scripts/find_testable_markets.pyThis will:
- Find recently resolved markets
- Check which have historical data
- Give you ready-to-test commands
Example output:
✅ Markets ready for backtesting:
python toolkit/execution-engine/src/execution_engine/backtester.py \
--market trump-popular-vote-2024
python toolkit/execution-engine/src/execution_engine/backtester.py \
--market bitcoin-above-100k-2024
cd toolkit/execution-engine
python src/execution_engine/backtester.py \
--market trump-popular-vote-2024 \
--config ../../config/trading.yamlThe backtest will output:
BACKTEST RESULTS
============================================================
Markets Tested: 1
Total Trades: 12
Winning Trades: 8
Win Rate: 66.7%
Total P&L: $145.50
ROI: 7.3%
============================================================
Create data/test_markets.txt:
trump-popular-vote-2024
bitcoin-above-100k-2024
fed-rate-decision-december
Run batch test:
while read market; do
python src/execution_engine/backtester.py --market "$market"
done < ../../data/test_markets.txt- Target: >55%
- Good: 55-65%
- Excellent: >65%
- Remember: This is per market, not annualized
- Compare: Against buy-and-hold
- Validate: Consistent across markets?
- Too few (<5): Not enough data to judge
- Good (10-20): Solid sample
- Many (>20): Strong evidence
-
Slippage Variation
- Backtest assumes constant slippage
- Reality: varies with market conditions
-
Market Impact
- Your orders move prices
- Bigger positions = more impact
- Not simulated in backtest
-
Execution Failures
- Orders can be rejected
- API can go down
- Network issues
-
Fee Changes
- Fees may vary by market
- Maker vs taker differences
-
Liquidity
- Historical orderbook depth not available
- Can't simulate partial fills
-
Look-Ahead Bias
- We know the market resolved
- Real trading has uncertainty
Add conservative assumptions:
# config/backtest_conservative.yaml
backtest:
slippage_pct: 0.5 # Pessimistic
fee_pct: 0.5 # Include fees
partial_fill_pct: 80 # Assume 80% fill rate
execution_failure_pct: 5 # 5% of trades failSign up at: https://adjacent.finance/api
# Add to .env
ADJACENT_API_KEY="adj_..."import os
import httpx
api_key = os.getenv("ADJACENT_API_KEY")
response = httpx.get(
"https://api.adjacent.finance/v1/polymarket/markets",
headers={"Authorization": f"Bearer {api_key}"}
)
print(response.status_code) # Should be 200If you've been running the paper trader with data recording:
ls -lh data/recordings/# See what markets you've recorded
zcat data/recordings/snapshots_*.jsonl.gz | \
jq -r '.market_question' | \
sort -uThe backtester will automatically find and use your recorded data.
- Win rate >55% consistently
- Positive ROI across different market types
- Results similar between backtest and paper trading
- Strategy works in both bull and bear markets
- Win rate 50-55% (marginal edge)
- High variance in results
- Works on some markets, fails on others
- Needs perfect execution to be profitable
- Win rate <50%
- Negative ROI overall
- Only 1-2 winning markets out of many
- Results dramatically different from paper trading
# 1. Find testable markets
python scripts/find_testable_markets.py
# 2. Test top 3 markets
python toolkit/execution-engine/src/execution_engine/backtester.py \
--market market-1
python toolkit/execution-engine/src/execution_engine/backtester.py \
--market market-2
python toolkit/execution-engine/src/execution_engine/backtester.py \
--market market-3
# 3. Aggregate and analyze
# (Results saved to data/backtest_results/)
# 4. If results good (>55% win rate):
# → Continue with paper trading
# 5. If results poor (<50% win rate):
# → Adjust parameters and retest- ✅ Run paper trading for 30 days
- ✅ Compare paper trading to backtest
- ✅ If both good → consider going live
- 🔄 Test different parameters
- 🔄 Focus on market types that work
- 🔄 Refine signal logic
⚠️ Don't trade this strategy⚠️ Go back to research⚠️ Test completely different approach
Backtesting ≠ Real Trading
-
✅ Good for: Finding obviously bad strategies
-
✅ Good for: Parameter optimization
-
✅ Good for: Understanding strategy behavior
-
❌ Not enough: Must paper trade
-
❌ Not perfect: Real world has more friction
-
❌ Not guarantee: Past ≠ future
Always validate with paper trading before live!
Try:
- Different market (use
find_testable_markets.py) - Adjacent API (paid but reliable)
- Wait and record your own data
- Normal if market had limited volatility
- Try markets with more volume
- Check if signals are too strict
- Check for look-ahead bias
- Verify slippage is included
- Test on out-of-sample markets
- Be skeptical!
Remember: @the_smart_ape made +86% with the RIGHT parameters and -50% with the WRONG ones. Backtest to find what works! 🎯