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 portfolio holdings. When paired with the Gamma API for market intelligence, you can construct an entirely automated prediction market trading bot.
Algorithmic trading extends far beyond institutional finance. The Polymarket API grants engineers direct access to the globe's most active prediction marketplace. Whether your goal is to automate a straightforward rebalancing approach or engineer a complex market-making system, this resource walks through all the essentials needed to launch your project.
API Architecture Overview
Polymarket makes available two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition specifications, and archived pricing information. Openly accessible, authentication not required - CLOB API (
clob.polymarket.com): Order submission, removal, asset allocation oversight, and live order book information. Mandates EIP-712 authorisation credentials
Authentication
CLOB API security operates across two distinct tiers:
- L1 Authentication (EIP-712): Cryptographically sign a structured message utilising your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign all API communications using the generated credentials. The signature encompasses the timestamp, HTTP method, 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 furnishes all requisite market intelligence:
// 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): Persists within the order book until execution or withdrawal
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Executes in full or terminates entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, terminates unmatched portion
WebSocket Streaming
To receive instantaneous market updates, establish a connection to the CLOB WebSocket interface:
// 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 movements across designated markets through WebSocket feeds
- Determine a moving average spanning the preceding 24-hour window
- Initiate purchases when quotations fall 10%+ beneath this threshold
- Close positions upon price normalisation back towards the average
- Apply Kelly criterion methodology for optimal position dimensioning
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently apply exponential backoff when encountering 429 status codes
- Leverage WebSockets for live information feeds rather than continuous polling
- Store your private key within environment configuration, never hardcode it
- Validate strategies on modest volumes prior to expanding positions
PolyGram participants gain entry to all these marketplaces via an intuitive dashboard — API coding is entirely optional. Start trading on PolyGram →