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 most active prediction market ecosystem. Whether your goal is to automate a straightforward rebalancing approach or construct an advanced market-making engine, this resource equips you with the essential knowledge to begin.
API Architecture Overview
Polymarket offers two distinct API interfaces:
- Gamma API (
gamma-api.polymarket.com): Supplies event information, market listings, condition details, and past performance metrics. Open to the public without requiring login credentials - CLOB API (
clob.polymarket.com): Enables order submission, removal, position tracking, and live order book information. Demands EIP-712 derived API credentials for access
Authentication
CLOB API security employs a dual-layer mechanism:
- L1 Authentication (EIP-712): Use your Ethereum private key to cryptographically sign a typed-data structure, generating API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every request with these 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 delivers comprehensive market information 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 types and validity windows:
- GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
- GTD (Good-Till-Date): Automatically expires at a designated timestamp
- FOK (Fill-Or-Kill): Either executes in full or gets rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder
WebSocket Streaming
For live 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 approach could operate as follows:
- Track market quotations across your chosen markets using WebSocket feeds
- Compute a moving average from the preceding 24-hour period
- Initiate purchases when quotes fall 10%+ beneath this average
- Exit positions once quotes recover to the 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
- Implement exponential backoff when encountering 429 rate-limit responses
- Favour WebSocket connections for live feeds rather than repeated polling
- Store your private key in environment variables, away from source code
- Validate strategies with modest capital before expanding exposure
PolyGram users gain access to these markets via a streamlined dashboard — no coding required. Start trading on PolyGram →