In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live price streams, and oversee your portfolio holdings. Paired with the Gamma API for market intelligence, you can construct a fully autonomous prediction market trading bot.
Algorithmic trading extends well beyond institutional finance desks. The Polymarket API grants programmers unrestricted entry to the globe's premier prediction marketplace. Whether your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making system, this resource walks you through every step required to begin.
API Architecture Overview
Polymarket offers two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event information, market listings, condition details, and past performance records. Openly accessible, authentication not required - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio oversight, and live order book information. Demands EIP-712 derived API credentials
Authentication
CLOB API security operates across two tiers:
- 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 your derived credentials. The signature encompasses the timestamp, HTTP method, 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 furnishes 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 varied time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
- GTD (Good-Till-Date): Terminates at a designated moment
- FOK (Fill-Or-Kill): Must execute in full or be rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, discards the remainder
WebSocket Streaming
To obtain instantaneous market information, 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 mean-reversion system could operate as follows:
- Observe price movements across chosen markets through WebSocket feeds
- Determine a moving average across the preceding 24-hour window
- Initiate purchases when price falls 10%+ beneath the moving average
- Close positions when price recovers to the moving average level
- Apply Kelly criterion methodology for optimal position sizing
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently apply exponential backoff when receiving 429 responses
- Favour WebSocket connections for live data rather than repeated polling
- Store your private key in environment variables, never embed it directly
- Validate strategies on modest holdings before expanding exposure
PolyGram users gain access to all these markets via a streamlined dashboard — no coding or API integration needed. Start trading on PolyGram →