In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing feeds, and oversee your portfolio holdings. When paired with the Gamma API for market intelligence, you gain the capability to construct an entirely automated prediction market trading bot.
Algorithmic trading extends well beyond institutional finance. The Polymarket API grants developers unrestricted access to the globe's most active prediction market. Whether your goal is to streamline a basic rebalancing approach or construct an advanced market-making bot, this resource walks you through all essential steps.
API Architecture Overview
Polymarket makes available two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, contract specifications, and archival pricing information. Openly accessible without login credentials - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio oversight, and instantaneous order book snapshots. Mandates EIP-712 authorised API tokens
Authentication
CLOB API security operates across two distinct stages:
- L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum private key to obtain API tokens (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign every request with your tokens. The signature encodes the timestamp, HTTP verb, endpoint, and payload content
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 intelligence required for your bot:
// 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 categories and execution parameters:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically expires at a predetermined moment
- FOK (Fill-Or-Kill): Executes in full or cancels entirely
- IOC (Immediate-Or-Cancel): Executes available quantity and removes unfilled remainder
WebSocket Streaming
To receive instantaneous 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 reverting-to-mean approach could operate as follows:
- Observe price movements across designated markets using WebSocket feeds
- Compute a moving average across the preceding day
- Initiate purchases when price falls 10%+ beneath the moving average
- Liquidate holdings once 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
- Incorporate exponential backoff handling for 429 status codes
- Favour WebSocket connections for live market data rather than continuous polling
- Store your private key within environment configuration, never hardcoded
- Validate approaches with minimal capital prior to expansion
PolyGram participants gain access to these entire market ecosystems via an intuitive dashboard — no coding expertise needed. Start trading on PolyGram →