In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and handle your portfolio. Paired with the Gamma API for market intelligence, you can construct a fully autonomous prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional traders. The Polymarket API grants developers unrestricted entry to the globe's premier prediction market. If your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making engine, this resource walks you through all the essentials.
API Architecture Overview
Polymarket offers two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Marketplace information — contests, trading pairs, event specifications, and archival records. Openly accessible, no credentials required - CLOB API (
clob.polymarket.com): Order submission, removal, holdings oversight, and instantaneous book snapshots. Demands EIP-712 derived API credentials
Authentication
CLOB API verification employs a dual-tier mechanism:
- L1 Authentication (EIP-712): Create a signed typed-data payload using your Ethereum account's secret key to produce API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Append a cryptographic signature to each call leveraging your derived credentials. The signature incorporates the moment in time, HTTP verb, endpoint, and request 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 supplies the marketplace information 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 immediate execution, limit orders, and varied duration settings:
- GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Executes entirely or gets rejected outright
- IOC (Immediate-Or-Cancel): Executes available quantity, discards unmatched portion
WebSocket Streaming
To obtain live feeds, establish a connection to the CLOB WebSocket gateway:
// 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 chosen markets using WebSocket feeds
- Determine an exponential moving average spanning the preceding day
- Initiate purchases when quotations sink 10%+ beneath the average
- Liquidate holdings once quotations recover to baseline
- Employ Kelly criterion methodology for stake determination
Rate Limits and Best Practices
- CLOB API: 100 calls per 10 seconds per credential set
- Consistently apply exponential backoff when receiving 429 status codes
- Favour WebSocket subscriptions for live information rather than continuous polling
- Safeguard your secret key within configuration files, away from repositories
- Validate approaches with minimal capital prior to expansion
PolyGram members gain entry to every crypto market through a streamlined dashboard — zero coding effort needed. Start trading on PolyGram →