Orderbook replay is the gold standard for backtesting, but it’s also the heaviest to iterate on. For first-pass strategy ideas, candles are much cheaper to crunch — and you can reconcile against the trade tape afterward to confirm that what your candle-based strategy “did” was actually achievable. This page covers the candle-first workflow and how to validate it against ground truth.Documentation Index
Fetch the complete documentation index at: https://docs.predexon.com/llms.txt
Use this file to discover all available pages before exploring further.
Two complementary endpoints
| Endpoint | Granularity | Use for |
|---|---|---|
/v2/polymarket/candlesticks/{condition_id} | 1m, 5m, 15m, 1h, 4h, 1d (auto-fit) | Fast pattern search, indicator-based strategies |
/v2/polymarket/trades | Per-fill | Reconciliation, exact-fill simulation, VWAP checks |
Pass 1 — fast candle-driven backtest
Pull condition-level candles and run your strategy in pandas. This is fast enough to grid-search parameters.Pass 2 — reconcile against the trade tape
For each candle bar where your strategy triggered, ask the trades endpoint what actually traded in that bar. Replace candle close with VWAP of executed trades, or check that there was enough volume to support your hypothetical size.- Was there volume? If
sum(sizes) < your_target_size, your strategy couldn’t have moved that much money without walking the book. - Was the candle close achievable? Compare candle
closeto the realized VWAP. Large divergences mean the close was a low-volume tick — not a price you could trade at. - Did your direction get hit? Filter trades by side. If your signal said “buy” but every executed trade in the bar was a sell, the book was offered down — you’d be paying through the spread.
Pass 3 — fall back to orderbook replay for the edge cases
Once you’ve reconciled against trades, you’ll find a handful of bars where:- Trades volume was thin
- Realized VWAP diverged from candle close
- Your size was a big chunk of the bar’s volume
A note on tokens vs conditions
- Candles by
condition_idgive you the market-level OHLCV (usually the Yes side by convention). - Candles by
token_id(/candlesticks/token/{token_id}) let you backtest either outcome independently. Use this if your strategy trades both sides. - Trades and orderbook are always per-token. Make sure all three are aligned to the same outcome when reconciling.
