Execution Simulation Order Book Data for Polymarket Backtests
Use historical order book data for execution simulation, slippage modeling, partial fills, and realistic Polymarket strategy backtests.
Execution simulation order book data is the difference between a signal backtest and a tradable backtest. A midpoint series can show whether an idea pointed in the right direction, but only historical bid and ask depth can show whether the order could have filled.
Why Execution Simulation Needs the Book
- Best bid and best ask define the real buy and sell prices.
- Depth at each level determines capacity and price impact.
- Wide spreads can erase otherwise profitable prediction-market signals.
- Partial fills matter when liquidity disappears near resolution.
Simulation Inputs
| Input | Use in simulation |
|---|---|
| Timestamped snapshots | Replay the market state your strategy would have seen. |
| Bid and ask ladders | Walk the book to estimate average fill price. |
| Resolution metadata | Compute final payoff and settlement-aware PnL. |
| Reference prices | Align crypto market movement with Polymarket probability changes. |
Basic Fill Logic
def simulate_buy(order_size, asks):
remaining = order_size
cost = 0
filled = 0
for level in asks:
take = min(remaining, level["size"])
cost += take * level["price"]
filled += take
remaining -= take
if remaining == 0:
break
return {"filled": filled, "avg_price": cost / filled if filled else None}