In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API lets you programmatically place orders, stream prices, and manage positions. Combined with the Gamma API for market data, you can build a fully automated prediction market trading bot.
Algorithmic trading extends far beyond institutional finance. The Polymarket API provides developers with comprehensive access to the globe's foremost prediction market platform. From automating straightforward portfolio adjustments to constructing advanced market-making systems, this resource outlines the foundational steps required for implementation.
API Architecture Overview
Polymarket makes available two distinct API services:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market specifications, condition identifiers, and archival pricing information. Publicly accessible without credentials - CLOB API (
clob.polymarket.com): Order submission, withdrawal, position tracking, and live order book snapshots. Demands EIP-712 authorisation credentials
Authentication
CLOB API authorisation operates across two distinct phases:
- L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum keypair to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign each request using the obtained 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 furnishes comprehensive market information required for bot operation:
// 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 various order classifications and temporal constraints:
- GTC (Good-Till-Cancelled): Persists within the order book until execution or withdrawal
- GTD (Good-Till-Date): Automatically cancels upon reaching a designated timestamp
- FOK (Fill-Or-Kill): Executes entirely or rejects entirely without partial fills
- IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder
WebSocket Streaming
For 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 would typically:
- Track market quotations across designated contracts through WebSocket feeds
- Determine a moving average across the preceding 24-hour window
- Initiate long positions when quotations fall 10%+ beneath the moving average
- Exit positions once quotations normalise toward the moving average
- Apply Kelly criterion methodology for position dimensioning
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Implement exponential backoff procedures when receiving 429 status codes
- Prioritise WebSocket subscriptions for live market feeds rather than repetitive polling cycles
- Store your private key within environment configuration, never embedded within application code
- Validate strategies using minimal capital before expanding position sizes
PolyGram participants gain streamlined access to these markets via an intuitive trading platform — technical API integration is unnecessary. Start trading on PolyGram →