Polymarket Historical Data API Python Guide
Use Python to fetch Polymarket historical data, order book snapshots, and resolved market metadata from the PolyHistorical API.
Polymarket historical data API Python workflows are useful when you want to pull order book snapshots into pandas, notebooks, backtesting engines, or research pipelines. PolyHistorical exposes resolved Polymarket market history through a simple REST API that works with standard Python HTTP clients.
Python Quick Start
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.polyhistorical.com/v1"
headers = {"X-API-Key": API_KEY}
markets = requests.get(
f"{BASE_URL}/markets",
params={"coin": "BTC", "market_type": "5m", "resolved": "true", "limit": 10},
headers=headers,
).json()
slug = markets["markets"][0]["slug"]
snapshots = requests.get(
f"{BASE_URL}/markets/{slug}/snapshots",
params={"include_orderbook": "true", "limit": 1000},
headers=headers,
).json()
What to Pull
- Market metadata for coin, timeframe, open time, close time, and resolution.
- Snapshot time series with UP and DOWN prices.
- Full order book depth when you need slippage or fill simulation.
- Reference price context for BTC, ETH, or SOL Up/Down markets.
Python Use Cases
| Workflow | Why Python fits |
|---|---|
| Notebook research | Load snapshots into pandas for spread, depth, and probability analysis. |
| Backtesting | Replay snapshots chronologically and simulate fills against bid/ask ladders. |
| Bulk exports | Persist normalized data to CSV, Parquet, DuckDB, or a warehouse. |
| Model training | Build features from order book imbalance, spread, liquidity, and resolution outcomes. |