In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables developers to submit orders programmatically, consume live price feeds, and oversee portfolio holdings. When paired with the Gamma API for market intelligence, you gain the ability to construct a completely autonomous prediction market trading bot.
Algorithmic trading extends well beyond institutional finance. The Polymarket API grants programmers unrestricted access to the planet's foremost prediction market infrastructure. Whether your objective is to streamline a straightforward rebalancing approach or engineer a complex market-making system, this resource walks through the entire setup process.
API Architecture Overview
Polymarket makes available two principal API surfaces:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market registries, condition hierarchies, and time-series pricing. Openly accessible, authentication unnecessary - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio tracking, and live order book snapshots. Mandates EIP-712 signed API credentials
Authentication
CLOB API security operates across two distinct tiers:
- L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum account's private key to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign each request using the generated credentials. The signature encompasses 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 supplies the complete set of market intelligence required for informed trading:
// 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 diverse time-in-force configurations:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically expires upon reaching a designated timestamp
- FOK (Fill-Or-Kill): Requires complete execution or total cancellation
- IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder
WebSocket Streaming
To obtain instantaneous market information, establish a connection to the CLOB WebSocket interface:
// Subscribe to order book updates
ws.send(JSON.stringify({
type: "subscribe",
channel: "market",
assets_id: TOKEN_ID
}));
Building a Simple Strategy
An elementary mean-reversion trading system could operate as follows:
- Track market quotations across your chosen venues through WebSocket feeds
- Determine a 24-hour rolling median price point
- Initiate purchases when quotation falls 10%+ beneath the computed median
- Liquidate holdings once quotation recovers to the median 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 apply exponential backoff when encountering 429 status codes
- Favour WebSocket connections for live market feeds rather than repetitive polling
- Store your private key within environment configuration, never embedded in source
- Validate approaches on minimal allocations prior to production deployment
PolyGram participants can engage with these markets via a streamlined dashboard — API coding is entirely optional. Start trading on PolyGram →