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 develop an entirely automated prediction market trading bot.
Algorithmic trading extends well beyond traditional finance institutions. The Polymarket API grants developers unrestricted entry to the globe's premier prediction market platform. Whether your goal is to streamline a straightforward rebalancing approach or develop an advanced market-making bot, this resource walks you through all essential steps.
API Architecture Overview
Polymarket makes available two primary APIs:
- Gamma API (
gamma-api.polymarket.com): Event information, market listings, conditions, and past performance data. Publicly accessible without sign-in requirements - CLOB API (
clob.polymarket.com): Order submission, removal, holding oversight, and live order book snapshots. Requires EIP-712 derived API credentials
Authentication
CLOB API security employs a dual-layer mechanism:
- L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum private key to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every API call with the obtained 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 required 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 various time-in-force settings:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Either executes in full or gets rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity and discards the remainder
WebSocket Streaming
To obtain live information, 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 might incorporate:
- Track pricing across your chosen markets using WebSocket feeds
- Determine an average price across the preceding 24-hour window
- Initiate purchases when price dips 10%+ beneath the mean
- Exit holdings when price recovers to the mean level
- Apply Kelly criterion methodology for stake determination
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Always apply exponential backoff when receiving 429 responses
- Favour WebSockets for live feeds rather than repeated polling
- Store your private key within environment settings, not hardcoded
- Validate approaches using modest amounts before expanding positions
PolyGram participants gain entry to all these markets via a streamlined dashboard — API coding is entirely optional. Start trading on PolyGram →