In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live price feeds, and handle your portfolio. Paired with the Gamma API for market intelligence, you can construct a fully autonomous prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional traders. The Polymarket API grants developers unrestricted access to the planet's foremost prediction market. Whether your aim is to streamline a straightforward rebalancing tactic or develop an advanced market-making engine, this resource walks you through everything required to begin.
API Architecture Overview
Polymarket makes available two primary APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and archival price information. Openly accessible, no authorisation required - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio oversight, and instantaneous order book visibility. Mandates EIP-712 derived API credentials
Authentication
CLOB API security employs a dual-stage mechanism:
- L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum account's secret key to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every API call with the obtained credentials. The signature incorporates the request's timestamp, 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 supplies the complete 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 facilitates market orders, limit orders, and varied time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains on the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Executes entirely or rejects entirely
- IOC (Immediate-Or-Cancel): Executes partially if necessary, discards unfilled portions
WebSocket Streaming
To receive instantaneous updates, establish a connection to the CLOB WebSocket service:
// 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:
- Observe price movements across designated markets using WebSocket feeds
- Compute a moving average spanning the preceding 24-hour interval
- Initiate buys when price declines 10%+ relative to the average
- Close positions when price recovers toward the average
- Employ Kelly criterion for optimal position sizing
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently employ exponential backoff when encountering 429 responses
- Favour WebSockets for live market data over repeated polling
- Store your secret key in configuration files, never hardcoded
- Validate strategies with minimal capital before expanding positions
PolyGram participants gain entry to all these markets via an intuitive dashboard — API coding is entirely optional. Start trading on PolyGram →