Complete guide to the Polymarket prediction market API. CLOB order book, Gamma Markets API, py-clob-client SDK, condition IDs, authentication, and how to add AI analysis.
import httpx# Fetch the top Polymarket markets by 24-hour volumeresp = httpx.get("https://gamma-api.polymarket.com/markets", params={ "limit": 10, "active": True, "order": "volume24hr", "ascending": False,})for market in resp.json(): yes_price = market["outcomePrices"][0] if market.get("outcomePrices") else "N/A" print(f"{market['question']} | YES: {yes_price} | Vol: ${float(market.get('volume24hr', 0)):,.0f}")
Polymarket is the largest crypto-native prediction market by trading volume, built on the Polygon blockchain. Markets settle in USDC, outcomes are binary (Yes/No), and prices represent implied probabilities — a Yes price of $0.65 means the market prices the event at 65% likely.Key architectural facts:
Order matching — Central Limit Order Book (CLOB), not AMM
Market identifiers — condition IDs (hex strings) for events, token IDs for individual outcomes
Two separate APIs — Gamma (discovery/metadata, public) and CLOB (trading, authenticated)
If you just need normalized market data across platforms without dealing with two APIs and HMAC signing, see the Rekko Markets API.
Polymarket splits its API into two completely separate services. Understanding which one to use for what is the first thing that trips up most developers.
Trading endpoints require three headers on every request: your API key, a Unix timestamp, and an HMAC-SHA256 signature over the request details.You generate API credentials from your Polymarket account. The secret is used to sign requests but is never sent over the wire.
Polymarket publishes an official Python SDK that wraps the CLOB API and handles authentication, order signing, and the Conditional Token Framework (CTF) interactions.
# List available marketsmarkets = client.get_markets()# Get order book for a specific tokenbook = client.get_order_book(token_id="YOUR_TOKEN_ID")print(f"Best bid: {book.bids[0].price if book.bids else 'none'}")print(f"Best ask: {book.asks[0].price if book.asks else 'none'}")# Place a limit buy orderorder = client.create_and_post_order( token_id="YOUR_TOKEN_ID", price=0.65, # Price per share in USDC size=100, # Number of shares side="BUY",)print(f"Order ID: {order['orderID']}")# Cancel an orderclient.cancel(order_id="YOUR_ORDER_ID")# Get open ordersopen_orders = client.get_orders()# Get positionspositions = client.get_positions()
Trading on Polymarket requires USDC on the Polygon network and CTF (Conditional Token Framework) approval. The SDK handles CTF interactions, but you must have funded your Polygon wallet with USDC first.
Maker and taker fees are low and vary by market. Polymarket’s fee structure has evolved over time — check their official docs for the latest schedule. All positions settle in USDC on Polygon (chain ID 137). Winning shares pay 1.00,losingsharespay0.00. Resolution uses the UMA Optimistic Oracle. Gas costs are minimal (typically < $0.01 per transaction).
You can layer AI-powered analysis on top of Polymarket by routing market data through an intelligence API. Here is a complete example that discovers markets on Polymarket, runs an independent analysis, and checks for cross-platform arbitrage.
# List Polymarket marketscurl "https://api.rekko.ai/v1/markets?source=polymarket&limit=5" \ -H "Authorization: Bearer YOUR_REKKO_API_KEY"# Trigger analysiscurl -X POST "https://api.rekko.ai/v1/markets/polymarket/0xabc123.../analyze" \ -H "Authorization: Bearer YOUR_REKKO_API_KEY"# Get completed analysis (poll status first, then retrieve)curl "https://api.rekko.ai/v1/markets/polymarket/0xabc123.../analysis" \ -H "Authorization: Bearer YOUR_REKKO_API_KEY"# Check for cross-platform arbitragecurl "https://api.rekko.ai/v1/arbitrage?min_spread=0.02" \ -H "Authorization: Bearer YOUR_REKKO_API_KEY"
You do not need to choose between the Polymarket API and an intelligence API. Use Polymarket’s CLOB directly for trade execution, and an intelligence API for analysis and decision-making.
Mixing up condition IDs and token IDs. Condition IDs identify the market. Token IDs identify specific outcomes (Yes/No). Trading endpoints use token IDs, not condition IDs.Forgetting the two-API split. If you call gamma-api.polymarket.com for order book data, you will not find it. Order books live on clob.polymarket.com.Stale outcomePrices from the Gamma API. The Gamma API prices may lag behind the live order book by a few seconds. For latency-sensitive applications, read the order book directly from the CLOB API.USDC and Polygon wallet setup. Before you can trade, you need USDC on the Polygon network (chain ID 137) and must approve the CTF contract. The py-clob-client SDK handles CTF approval, but wallet funding is on you.No sandbox environment. Polymarket does not offer a testnet or paper trading mode. To test order placement, you are working with real funds. Use very small order sizes when developing.