In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price streams, and oversee your holdings. When paired with the Gamma API for market intelligence, you can construct an end-to-end automated prediction market trading bot.
Algorithmic trading extends well beyond institutional finance. The Polymarket API provides developers with unrestricted access to the planet's leading prediction market. If your goal is to streamline a straightforward rebalancing tactic or engineer an advanced market-making bot, this resource walks you through all the essentials.
API Architecture Overview
Polymarket makes available two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and archival pricing. Open to the public with no sign-in requirement - CLOB API (
clob.polymarket.com): Order submission, removal, position tracking, and live order book snapshots. Mandates EIP-712 authorised API keys
Authentication
CLOB API security operates across two tiers:
- L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum secret key to produce API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign every API call using the generated credentials. The signature encodes the request timestamp, HTTP verb, endpoint path, and payload
Example credential derivation (JavaScript):
import { ethers } from "ethers";
const wallet = new ethers.Wallet(PRIVATE_KEY);
const domain = { name: "ClobAuthDomain", ... };
const types = { ClobAuth: [{ name: "address", type: "address" }, ...] };
const signature = await wallet.signTypedData(domain, types, value);
// POST to /auth/derive-api-key with the signature
Fetching Market Data
The Gamma API supplies the complete set of market information required:
// List active events
GET https://gamma-api.polymarket.com/events?active=true&limit=100
// Get specific market details
GET https://gamma-api.polymarket.com/markets/{conditionId}
// Historical price data
GET https://gamma-api.polymarket.com/markets/{conditionId}/prices
Placing Orders
The CLOB API accommodates market orders, limit orders, and varied time-in-force specifications:
- GTC (Good-Till-Cancelled): Remains in the book until executed or withdrawn
- GTD (Good-Till-Date): Lapses at a predetermined moment
- FOK (Fill-Or-Kill): Executes entirely or gets rejected outright
- IOC (Immediate-Or-Cancel): Executes available volume, discards the balance
WebSocket Streaming
To obtain instantaneous information, establish a link to the CLOB WebSocket service:
// Subscribe to order book updates
ws.send(JSON.stringify({
type: "subscribe",
channel: "market",
assets_id: TOKEN_ID
}));
Building a Simple Strategy
A straightforward mean-reversion approach could:
- Track price movements across chosen markets using WebSocket feeds
- Compute a moving average spanning the preceding 24-hour window
- Initiate purchases when the price falls 10%+ beneath the moving average
- Liquidate holdings once price recovers to the moving average level
- Apply Kelly criterion methodology for position dimensioning
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Always implement exponential backoff on 429 responses
- Favour WebSockets for live feeds rather than continuous polling
- Safeguard your secret key using environment configuration, never hardcode it
- Validate strategies with modest stakes before ramping exposure
PolyGram members gain entry to all these markets via a streamlined dashboard — API coding is entirely optional. Start trading on PolyGram →