In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live pricing streams, and oversee your holdings. When paired with the Gamma API for market intelligence, you gain the capability to construct an end-to-end automated prediction market trading bot.
Algorithmic trading extends well beyond institutional finance. The Polymarket API grants engineers direct access to the globe's premier prediction market infrastructure. Whether your aim is to streamline a basic portfolio rebalancing tactic or engineer a complex market-making system, this resource walks through all essential steps for implementation.
API Architecture Overview
Polymarket makes available two principal API interfaces:
- Gamma API (
gamma-api.polymarket.com): Market specifics — competitions, trading pairs, contract states, and temporal pricing records. Publicly accessible, authentication unnecessary - CLOB API (
clob.polymarket.com): Order submission, removal, holdings administration, and instantaneous order ledger snapshots. Mandates EIP-712 sourced API tokens
Authentication
CLOB API security operates across two distinct stages:
- L1 Authentication (EIP-712): Cryptographically sign a structured-data payload using your Ethereum account key to generate API tokens (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign every CLOB request utilising your generated tokens. The signature encompasses the request timestamp, HTTP verb, endpoint path, and payload contents
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 furnishes comprehensive market catalogue and reference material:
// 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 execution orders, restricted-price orders, and varied execution duration settings:
- GTC (Good-Till-Cancelled): Persists in the order ledger until executed or withdrawn
- GTD (Good-Till-Date): Automatically terminates at a predetermined moment
- FOK (Fill-Or-Kill): Requires complete execution or full cancellation
- IOC (Immediate-Or-Cancel): Executes available quantity, terminates unfilled portion
WebSocket Streaming
To obtain live market feeds, establish a connection to the CLOB WebSocket gateway:
// Subscribe to order book updates
ws.send(JSON.stringify({
type: "subscribe",
channel: "market",
assets_id: TOKEN_ID
}));
Building a Simple Strategy
An elementary reversion-to-mean system could function as follows:
- Track price movements across selected markets through WebSocket connections
- Compute an exponential moving average spanning the preceding day
- Initiate long positions when quotations fall 10%+ beneath the computed average
- Exit positions upon price convergence with the average level
- Apply Kelly criterion methodology for stake determination
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Always deploy exponential backoff protocols upon receiving 429 status codes
- Favour WebSocket subscriptions for live information over repetitive polling cycles
- Store your account key in configuration files, never hardcoded into repositories
- Validate strategies using minimal capital prior to full-scale deployment
PolyGram participants gain entry to all these marketplaces via an intuitive dashboard — API coding entirely optional. Start trading on PolyGram →