What is the Polymarket API?
The Polymarket API (also known as the CLOB API) is a free, public REST API that gives you access to real-time prediction market data. You can fetch current market prices, historical trades, orderbook depth, and metadata for every market on the platform.
Unlike most financial data APIs, Polymarket does not require an API key for reading public data. This makes it one of the most accessible prediction market data sources available to developers, researchers, and data analysts.
Free & Open
No API key, no signup, no rate-limit tiers. Public data is freely available.
Real-Time Data
Get live prices, orderbook snapshots, and trade data updated every second.
Rich Market Data
Access metadata, descriptions, volume, and liquidity for thousands of markets.
Easy to Integrate
Standard REST JSON responses. Works with Python, JavaScript, or any language.
Quick Start
Getting started with the Polymarket API takes less than a minute. Here is everything you need to know:
https://clob.polymarket.com
No API key required for public endpoints. Just send HTTP requests directly.
All responses are JSON. Standard HTTP status codes apply.
Public endpoints are rate-limited to prevent abuse. Keep requests under ~10 per second from a single IP. If you exceed the limit, you will receive a 429 response.
For market metadata and event info, you can also use https://gamma-api.polymarket.com
API Endpoints
Here are the core endpoints you will use most often. All endpoints accept GET requests and return JSON responses.
/marketsList all marketsReturns a paginated list of all available markets on Polymarket, including metadata like question, description, end date, and current token IDs.
GET https://clob.polymarket.com/markets?next_cursor=MA==
Supports pagination via next_cursor parameter.
/markets/{id}Get single marketReturns detailed information about a specific market, including both token IDs (YES and NO), description, category, and resolution source.
GET https://clob.polymarket.com/markets/0x1234...abcd
The id is the condition_id of the market.
/pricesGet current pricesFetches the current mid-market price for one or more token IDs. This is the fastest way to get the latest odds without fetching the entire orderbook.
GET https://clob.polymarket.com/prices?token_id=0x1234...&side=buy
Use token_id and side (buy/sell) parameters.
/tradesGet recent tradesReturns a list of recent trades for a given market. Useful for tracking volume, detecting whale activity, and building historical price charts.
GET https://clob.polymarket.com/trades?asset_id=0x1234...&limit=50
Supports limit and after parameters for pagination.
Code Examples
Below are working code examples in Python and JavaScript to get you started quickly. Copy and paste these into your project to begin fetching Polymarket data immediately.
Python Example
This script fetches all markets from the CLOB API and prints the first five results. You need the requests library installed (pip install requests).
#!/usr/bin/env python3
"""
Fetch Polymarket market data via the CLOB API.
No API key required for public endpoints.
"""
import requests
import json
CLOB_BASE = "https://clob.polymarket.com"
GAMMA_BASE = "https://gamma-api.polymarket.com"
def get_markets(limit=5):
"""Fetch a list of active markets."""
url = f"{CLOB_BASE}/markets"
params = {"next_cursor": "MA=="}
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()
return data
def get_market_price(token_id: str):
"""Get the current price for a specific token."""
url = f"{CLOB_BASE}/prices"
params = {"token_id": token_id, "side": "buy"}
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
return response.json()
def get_orderbook(token_id: str):
"""Get the full orderbook for a token."""
url = f"{CLOB_BASE}/book"
params = {"token_id": token_id}
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()
return {
"best_bid": data.get("bids", [{}])[0],
"best_ask": data.get("asks", [{}])[0],
"bid_depth": len(data.get("bids", [])),
"ask_depth": len(data.get("asks", []))
}
def get_recent_trades(asset_id: str, limit=20):
"""Fetch recent trades for a market."""
url = f"{CLOB_BASE}/trades"
params = {"asset_id": asset_id, "limit": limit}
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
# 1. List markets
print("=== Fetching Markets ===")
markets = get_markets()
for market in markets.get("data", [])[:5]:
print(f" {market.get('question', 'N/A')}")
tokens = market.get("tokens", [])
for token in tokens:
tid = token.get("token_id", "")
print(f" Token: {tid[:20]}...")
# 2. Get a price (replace with a real token_id)
# price = get_market_price("0x1234...")
# print(f"Current price: {price}")
print("\nDone! Customize the token IDs above.")JavaScript / Node.js Example
This example uses the built-in fetch API (Node.js 18+ or any modern browser). No external dependencies required.
/**
* Fetch Polymarket data using the CLOB API.
* Works in Node.js 18+ and modern browsers.
*/
const CLOB_BASE = "https://clob.polymarket.com";
async function getMarkets() {
const res = await fetch(`${CLOB_BASE}/markets?next_cursor=MA==`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
async function getPrice(tokenId) {
const res = await fetch(
`${CLOB_BASE}/prices?token_id=${tokenId}&side=buy`
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
async function getRecentTrades(assetId, limit = 20) {
const res = await fetch(
`${CLOB_BASE}/trades?asset_id=${assetId}&limit=${limit}`
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
}
// Main
(async () => {
console.log("=== Fetching Markets ===");
const markets = await getMarkets();
const items = markets.data?.slice(0, 5) || [];
for (const market of items) {
console.log(` ${market.question}`);
for (const token of market.tokens || []) {
console.log(` Token: ${token.token_id?.slice(0, 20)}...`);
}
}
console.log("\nDone!");
})();gamma-api.polymarket.com/events.Building a Trading Bot
Once you can fetch market data, the next step for many developers is building an automated bot that monitors prices, detects opportunities, or executes trades. Here is a high-level architecture overview:
Polls the CLOB API every 5-10 seconds for price updates and new trades.
Analyzes price movements, detects anomalies, and identifies arbitrage opportunities.
Sends notifications via Telegram, Discord, or email when signals trigger.
Stores historical data in SQLite or PostgreSQL for backtesting and analysis.
Why You Need a VPS for 24/7 Operation
Running an API bot on your laptop is fine for testing, but for production use you need a VPS (Virtual Private Server). Here is why:
- 24/7 Uptime: Markets never sleep. Your bot should not either. A VPS stays online even when your laptop is off.
- Low Latency: A European VPS (London/Frankfurt) has 10-15ms latency to Polymarket's servers, compared to 80-150ms from a home connection.
- Reliable Network: VPS providers offer 99.9% uptime SLAs. Your home internet does not.
- Cost Effective: A basic VPS starts at $5-6/month. That is less than a coffee per week.
Rate Limits & Best Practices
To keep your integration running smoothly and avoid getting blocked, follow these best practices when working with the Polymarket API:
- Do Not Poll Too Frequently
Keep your polling interval at 5-10 seconds minimum. Hammering the API with sub-second requests will get your IP rate-limited (HTTP 429).
- Use WebSockets for Real-Time Data
For sub-second updates, connect to Polymarket's WebSocket feed instead of polling the REST API. This reduces load on both sides and gives you faster data.
- Cache Responses Locally
Market metadata (names, descriptions, token IDs) rarely changes. Cache it locally and only refresh every few hours. This dramatically reduces your API calls.
- Handle Errors Gracefully
Always implement retry logic with exponential backoff. The API can return 5xx errors during maintenance windows. Never crash on a single failed request.
- Respect Rate Limits
If you receive a 429 response, back off immediately. Wait at least 30 seconds before retrying. Repeated violations may result in a longer IP ban.
Common Use Cases
Here are the most popular things developers build with the Polymarket API:
Price Monitoring
Track specific markets and get alerts when odds shift beyond a threshold. Perfect for staying informed on elections, sports, or crypto events.
Arbitrage Detection
Compare prices across Polymarket, Kalshi, and other platforms. Detect mispricing and risk-free profit opportunities automatically.
Portfolio Tracking
Build a dashboard that tracks your open positions, unrealized P&L, and historical performance across all your Polymarket bets.
Research & Analysis
Analyze prediction market accuracy, study crowd wisdom, or build academic datasets on forecasting. Great for journalism and data science projects.
All of these use cases benefit from a dedicated server that runs 24/7. A VPS ensures your bot never misses a data point, even while you sleep.
Frequently Asked Questions
No. All public market data endpoints (markets, prices, trades, orderbook) are available without authentication. You only need API keys if you want to place orders or manage positions programmatically.
Yes, reading public data is completely free. There are no paid tiers or usage fees. However, you should respect rate limits to avoid being temporarily blocked.
The CLOB API (clob.polymarket.com) handles trading data: prices, orderbooks, and trades. The Gamma API (gamma-api.polymarket.com) provides market metadata: event descriptions, categories, images, and resolution sources. Most projects use both together.
The public data API is accessible worldwide, including from the US. Reading market data is not restricted. However, placing trades on Polymarket from the US is prohibited under their terms of service due to regulatory constraints. This guide covers data access only.
Polymarket offers WebSocket connections for real-time streaming data. This is more efficient than REST polling for use cases that need sub-second updates. Check the official Polymarket documentation for WebSocket endpoint details and subscription message formats.
