In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and oversee your 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. The Polymarket API grants engineers complete access to the planet's premier prediction market ecosystem. Whether your goal is to streamline a straightforward rebalancing approach or engineer an advanced market-making bot, this resource covers all the essentials to begin.
API Architecture Overview
Polymarket makes available two primary APIs:
- Gamma API (
gamma-api.polymarket.com): Event information, market catalogues, conditions, and time-series pricing. Publicly accessible without requiring authentication - CLOB API (
clob.polymarket.com): Order submission, removal, position tracking, and live order book snapshots. Mandates EIP-712 derived API credentials
Authentication
CLOB API security employs a dual-layer mechanism:
- L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum account's private key to generate API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every request sent to the API with your generated credentials. The signature incorporates the request timestamp, HTTP verb, endpoint path, 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 furnishes the full spectrum of market information required:
// 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 various time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically expires after a designated timestamp
- FOK (Fill-Or-Kill): Executes in full or cancels entirely
- IOC (Immediate-Or-Cancel): Executes available quantity and cancels unfilled remainder
WebSocket Streaming
For instantaneous market information, establish a connection to the CLOB WebSocket feed:
// 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 could operate as follows:
- Observe price movements across your chosen markets using WebSocket feeds
- Compute a moving average across the preceding 24-hour window
- Initiate a purchase when price declines 10%+ relative to the moving average
- Exit the position once price recovers toward the moving average level
- Apply Kelly criterion methodology for optimal position dimensioning
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently deploy exponential backoff logic when receiving 429 status codes
- Leverage WebSocket connections for live updates rather than continuous polling
- Store your private key in environment configuration files, never embedded in source
- Validate strategies with minimal capital allocation before expanding position sizes
PolyGram participants gain entry to all these markets via an intuitive dashboard — no coding skills necessary. Start trading on PolyGram →