In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price streams, and handle your portfolio. Paired with the Gamma API for market information, you can construct a completely self-executing prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional investors. The Polymarket API provides developers with unrestricted access to the globe's foremost prediction market platform. Whether you're looking to streamline a straightforward rebalancing approach or develop an advanced market-making bot, this resource walks you through all the essentials.
API Architecture Overview
Polymarket makes available two primary APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and past performance records. Freely accessible without login credentials - CLOB API (
clob.polymarket.com): Submitting trades, removing orders, controlling holdings, and accessing live order book snapshots. Demands EIP-712 derived API credentials
Authentication
CLOB API security operates across two distinct stages:
- L1 Authentication (EIP-712): Create a signed typed-data payload using your Ethereum wallet's private key to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every call to the API using the obtained credentials. The signature incorporates the request time, HTTP verb, resource 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 essential market 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 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 cancels at a predetermined moment
- FOK (Fill-Or-Kill): Either executes fully or gets rejected entirely
- 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
A straightforward mean-reversion approach could operate as follows:
- Track price movements across selected markets using WebSocket feeds
- Compute an exponential moving average spanning the preceding day
- Purchase when the price declines 10%+ relative to the computed average
- Liquidate holdings once the price recovers 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
- Consistently apply exponential backoff when encountering 429 status codes
- Favour WebSocket connections for live information rather than repeated polling
- Store your wallet's private key within environment settings, never hardcoded
- Validate strategies with minimal capital before expanding positions
PolyGram members gain entry to all these markets via an intuitive dashboard — coding expertise is optional. Start trading on PolyGram →