In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live price feeds, and oversee your holdings. When paired with the Gamma API for market intelligence, you gain the tools to construct an entirely autonomous prediction market trading bot.
Algorithmic trading extends well beyond institutional finance. The Polymarket API grants developers unrestricted entry to the globe's premier prediction market platform. Whether your objective is to streamline a basic portfolio rebalancing approach or construct an advanced market-making bot, this resource covers all essential information required to begin.
API Architecture Overview
Polymarket makes available two distinct APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition specifications, and archival pricing information. Publicly accessible, authentication not required - CLOB API (
clob.polymarket.com): Order submission, removal, holding oversight, and instantaneous order book snapshots. Demands EIP-712 derived API credentials
Authentication
CLOB API security comprises two distinct stages:
- L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign every API call using the generated credentials. The signature incorporates 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 delivers comprehensive market information:
// 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 numerous time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Must execute in full or be rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder
WebSocket Streaming
For live market information, establish a connection to the CLOB WebSocket channel:
// 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 algorithm might execute the following:
- Track price movements across designated markets through WebSocket feeds
- Compute a moving average across the preceding 24-hour window
- Initiate purchases when prices fall 10%+ beneath the moving average
- Exit positions once prices normalise toward the average
- Employ Kelly criterion methodology for position dimensioning
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently apply exponential backoff when receiving 429 responses
- Favour WebSocket subscriptions over repetitive polling for live updates
- Store your private key within environment configuration, never hardcoded
- Validate strategies using modest capital before expanding positions
PolyGram participants can engage with all these markets via a streamlined interface — no API coding necessary. Start trading on PolyGram →