In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders via code, consume live price feeds, and oversee your holdings. When paired with the Gamma API for market intelligence, constructing an end-to-end automated prediction market trading bot becomes straightforward.
Automated trading strategies are no longer confined to institutional finance. The Polymarket API provides developers with unrestricted access to the globe's premier prediction market ecosystem. Whether your goal is to streamline a basic portfolio rebalancing tactic or engineer an advanced market-making system, this resource equips you with all necessary knowledge to begin.
API Architecture Overview
Polymarket makes available two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event listings, market specifications, condition identifiers, and archival pricing information. Openly accessible without sign-in requirements - CLOB API (
clob.polymarket.com): Submission and withdrawal of orders, position administration, and live order book snapshots. Demands EIP-712 authorisation credentials
Authentication
The CLOB API employs a dual-tier security model:
- L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum account's secret key to generate authorisation parameters (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Affix a cryptographic signature to every request using your generated parameters. This signature incorporates the request's temporal marker, 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 furnishes comprehensive market intelligence for your applications:
// 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 execution parameters:
- GTC (Good-Till-Cancelled): Persists in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically terminates at a predetermined moment
- FOK (Fill-Or-Kill): Executes in full or not at all
- IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder
WebSocket Streaming
To obtain instantaneous market information, establish a connection to the CLOB WebSocket channel:
// 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 these steps:
- Track price movements across designated markets using WebSocket feeds
- Compute a moving average spanning the preceding 24-hour window
- Initiate a purchase when the price declines by 10% or more relative to the average
- Exit the position once the price recovers toward the average level
- Employ Kelly criterion methodology for determining stake magnitudes
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently employ exponential backoff when encountering 429 status codes
- Prioritise WebSocket connections for live market data rather than repeated polling cycles
- Store your account's secret key within environment configuration, never hardcoded in source files
- Validate strategies using minimal capital before expanding to larger positions
PolyGram users gain access to these entire market ecosystems via an intuitive dashboard — coding expertise remains optional. Start trading on PolyGram →