In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and oversee your holdings. When paired with the Gamma API for market intelligence, you gain the foundation to construct an entirely self-executing prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional finance. The Polymarket API grants engineers unrestricted access to the planet's most active prediction market. Whether your aim is to streamline a basic rebalancing workflow or engineer a cutting-edge market-making system, this resource walks you through all the essentials.
API Architecture Overview
Polymarket makes available two primary interfaces:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and archival pricing information. Openly accessible, no credentials required - CLOB API (
clob.polymarket.com): Order submission, order removal, position tracking, and live order book snapshots. Mandates EIP-712 signed API credentials
Authentication
CLOB API security operates across two tiers:
- L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum secret key to produce API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign every request using the generated credentials. The signature encompasses the request timestamp, HTTP verb, 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 supplies the complete set of 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 diverse time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Executes in full or gets rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, discards unfilled portion
WebSocket Streaming
To obtain instantaneous updates, 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 would:
- Track price movements across chosen markets using WebSocket feeds
- Compute a moving average spanning the preceding day
- Initiate a purchase when price falls 10%+ beneath the average
- Exit the position once price normalises toward 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 implement exponential backoff on 429 responses
- Leverage WebSockets for live information rather than continuous polling
- Store your secret key in environment variables, never hardcoded
- Validate strategies on minimal capital before increasing exposure
PolyGram participants gain entry to all these markets via an intuitive dashboard — API coding is completely optional. Start trading on PolyGram →