Getting Polymarket Data Programmatically
TL;DR
- - Polymarket provides REST and WebSocket APIs for market data, orderbook, and trades
- - Use the CLOB API for real-time orderbook data and the Gamma API for market metadata
- - Historical trade data is available through the API and on-chain
Polymarket is a prediction market platform where users trade on the outcomes of real-world events. Developers access Polymarket data through its API suite for building dashboards, analytics tools, trading bots, and data feeds.
API overview
Polymarket provides several API endpoints:
| API | Purpose | Auth required |
|---|---|---|
| Gamma API | Market metadata, conditions, outcomes | No |
| CLOB API | Orderbook, trades, prices | API key for trading |
| WebSocket | Real-time price and trade updates | No |
Market data
Listing active markets
const response = await fetch(
"https://gamma-api.polymarket.com/markets?closed=false&limit=100"
);
const markets = await response.json();
for (const market of markets) {
console.log(`${market.question}: ${market.outcomePrices}`);
}
Each market includes:
question: the event being predicted.outcomePrices: current prices (probabilities) for each outcome.volume: total trading volume.liquidity: current orderbook depth.endDate: when the market resolves.
Getting a specific market
const market = await fetch(
`https://gamma-api.polymarket.com/markets/${conditionId}`
).then((r) => r.json());
Real-time prices
WebSocket feed
Subscribe to price updates:
const ws = new WebSocket("wss://ws-subscriptions-clob.polymarket.com/ws/market");
ws.onopen = () => {
ws.send(JSON.stringify({
type: "market",
assets_id: tokenId,
}));
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log("Price update:", data);
};
Orderbook
const orderbook = await fetch(
`https://clob.polymarket.com/book?token_id=${tokenId}`
).then((r) => r.json());
console.log("Bids:", orderbook.bids);
console.log("Asks:", orderbook.asks);
Trade history
const trades = await fetch(
`https://clob.polymarket.com/trades?market=${conditionId}&limit=100`
).then((r) => r.json());
for (const trade of trades) {
console.log(`${trade.side} ${trade.size} @ ${trade.price} — ${trade.timestamp}`);
}
Building a dashboard
Common data points for a Polymarket dashboard:
- Market overview: question, current odds, volume, time to resolution.
- Price chart: historical price (odds) over time.
- Orderbook depth: bid/ask levels and sizes.
- Recent trades: latest trades with size and price.
- Volume analytics: daily/hourly volume trends.
Data pipeline
For analytics or research, build a data pipeline:
Polymarket API → Your Consumer → Database → Dashboard/Analysis
- Poll the Gamma API periodically for market metadata.
- Stream WebSocket for real-time price and trade data.
- Store in a database (PostgreSQL, ClickHouse).
- Query and visualize for analysis or display.
Rate limits
Polymarket APIs have rate limits:
- Gamma API: moderate limits, suitable for periodic polling.
- CLOB API: rate-limited per API key.
- WebSocket: connection limits apply.
Cache responses and use WebSocket streams instead of polling for real-time data.
FAQ
Do I need an API key to read Polymarket data? No, for reading market data, prices, and public trades. An API key is required for placing orders and accessing private trading endpoints.
Is Polymarket data on-chain? Polymarket uses a hybrid architecture. Market resolution and settlement happen on-chain, while the orderbook (CLOB) is off-chain for performance. On-chain data can be accessed through blockchain explorers and indexers.
Can I backtest trading strategies with Polymarket data? Yes. Collect historical price and trade data through the API. Store it locally and run your backtesting logic against it.
What format are Polymarket prices? Prices are between 0 and 1, representing the probability of an outcome. A price of 0.75 means the market assigns a 75% probability to that outcome.
Updated: