In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing, and control your holdings. When paired with the Gamma API for market intelligence, you can construct a completely autonomous prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional firms. The Polymarket API grants engineers direct access to the planet's foremost prediction market infrastructure. Whether your goal is to streamline a basic rebalancing approach or engineer an advanced market-making system, 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, contract specifications, and past performance records. Open to the public with no login required - CLOB API (
clob.polymarket.com): Submission and withdrawal of orders, position tracking, and live order book snapshots. Demands EIP-712 authorisation credentials
Authentication
CLOB API security operates across two tiers:
- L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum key to produce API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign every API call with your derived credentials. The signature incorporates the timestamp, HTTP verb, endpoint path, and request 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 all essential 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 instant fills, pegged orders, and varied execution modes:
- GTC (Good-Till-Cancelled): Persists within the order book until matched or withdrawn
- GTD (Good-Till-Date): Automatically lapses at a designated moment
- FOK (Fill-Or-Kill): Executes entirely or rejects outright
- IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder
WebSocket Streaming
To receive live market signals, establish a connection to the CLOB WebSocket feed:
// Subscribe to order book updates
ws.send(JSON.stringify({
type: "subscribe",
channel: "market",
assets_id: TOKEN_ID
}));
Building a Simple Strategy
A straightforward reversion-to-mean bot could operate as follows:
- Track price movements across chosen markets using WebSocket feeds
- Compute a 24-hour moving average
- Enter long positions when price falls 10%+ beneath the average
- Exit when price converges back to the average
- 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 logic when receiving 429 status codes
- Favour WebSocket subscriptions over repetitive polling for live feeds
- Store your private key in environment variables, not hardcoded
- Validate strategies with modest capital before expanding exposure
PolyGram members gain entry to all these markets via an intuitive dashboard — API coding is unnecessary. Start trading on PolyGram →