Polymarket Order Book API: Historical Depth for Backtesting
Use the PolyHistorical Polymarket order book API to fetch historical Level-2 bid/ask depth, market metadata, and snapshots for backtesting.
The Polymarket order book API from PolyHistorical is designed for historical analysis. It gives developers access to archived Level-2 order book snapshots, not just a live top-of-book quote or recent price history.
Historical API vs Live Order Book API
| Need | Live order book API | PolyHistorical API |
|---|---|---|
| Current bid/ask | Yes | Historical snapshots |
| Backtesting | Limited | Built for tick-by-tick replay |
| Resolved markets | Often unavailable | Archived after resolution |
| Full depth | Depends on endpoint | Every bid, ask, and price level |
| BTC/ETH/SOL Up/Down history | Not the focus | Core coverage |
Core Endpoints
GET /v1/markets
GET /v1/markets/{slug}
GET /v1/markets/{slug}/snapshots
GET /v1/markets/by-market-id/{id}/snapshots
Example Workflow
- List markets filtered by coin and timeframe.
- Select a resolved market slug.
- Fetch snapshots with
include_orderbook=true. - Walk the bid/ask ladders to simulate fills.
- Store results for strategy evaluation or research.
Python Example
import requests
BASE = "https://api.polyhistorical.com/v1"
headers = {"X-API-Key": "your_api_key"}
markets = requests.get(BASE + "/markets", params={"coin": "BTC", "market_type": "5m"}, headers=headers).json()
slug = markets["markets"][0]["slug"]
snapshots = requests.get(
BASE + "/markets/" + slug + "/snapshots",
params={"include_orderbook": "true", "limit": 1000},
headers=headers
).json()
Best For
- Trading bots that need historical training data
- Backtesting engines that model slippage
- Market microstructure research
- Liquidity and spread analysis on resolved Polymarket markets