In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing, and oversee your portfolio. When paired with the Gamma API for market intelligence, you can construct an end-to-end automated prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional traders. The Polymarket API grants engineers unrestricted access to the planet's premier prediction market ecosystem. Whether your goal is to streamline a straightforward rebalancing tactic or engineer a high-performance market-making bot, this resource walks you through the essentials.
API Architecture Overview
Polymarket offers two principal interfaces:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, conditions, and price history. Unrestricted access, authentication unnecessary - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio oversight, and live order book snapshots. Demands EIP-712 derived API credentials
Authentication
CLOB API security operates across two tiers:
- L1 Authentication (EIP-712): Sign a structured message using your Ethereum secret key to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every API call with your derived credentials. The signature incorporates the timestamp, HTTP verb, endpoint, 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 all the market information your bot requires:
// 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 assorted time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
- GTD (Good-Till-Date): Lapses at a predetermined moment
- FOK (Fill-Or-Kill): Executes wholly or gets rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder
WebSocket Streaming
For 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
A straightforward mean-reversion approach could operate as follows:
- Track pricing across your chosen markets through WebSocket feeds
- Compute a moving average across the preceding 24-hour window
- Initiate purchases when quotations dip 10%+ beneath the moving average
- Exit holdings once quotations normalise to the moving average
- Employ Kelly criterion methodology for position dimensioning
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Deploy exponential backoff whenever receiving 429 status codes
- Favour WebSockets for live information rather than continuous polling
- Store your secret key in environment configuration, not hardcoded
- Validate approaches with minimal capital before expanding positions
PolyGram participants gain entry to all these markets via an intuitive dashboard — API coding entirely optional. Start trading on PolyGram →