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 account positions. When paired with the Gamma API for market intelligence, you can construct a completely autonomous prediction market trading bot.
Algorithmic trading belongs to everyone, not just institutional finance. The Polymarket API opens the world's largest prediction market to developer automation. Whether your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making engine, this resource walks you through the essentials.
API Architecture Overview
Polymarket makes available two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and time-series pricing. Openly accessible without credentials - CLOB API (
clob.polymarket.com): Order submission, removal, account holdings, and live order book snapshots. Demands EIP-712 signed API credentials
Authentication
CLOB API security operates across two tiers:
- L1 Authentication (EIP-712): Sign a structured message using your Ethereum key to generate API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every request with your generated credentials. The signature incorporates the timestamp, HTTP verb, endpoint path, and 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 market intelligence required for your bots:
// 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 varied time-in-force instructions:
- GTC (Good-Till-Cancelled): Remains in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically expires at a designated moment
- FOK (Fill-Or-Kill): Executes fully or rejects entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder
WebSocket Streaming
To obtain live market feeds, establish a connection to the CLOB WebSocket channel:
// 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 would:
- Track pricing movements across your target markets through WebSocket feeds
- Determine a moving average across the preceding 24-hour window
- Initiate purchases when quotes sink 10%+ beneath the moving average
- Exit positions when valuations recover to the moving average level
- Apply Kelly criterion methodology for stake determination
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Implement exponential backoff when receiving 429 rate-limit responses
- Favour WebSocket subscriptions for live market data rather than repeated polling
- Store your private key in environment configuration, never hardcode it
- Validate your approach using minimal capital before expanding position sizes
PolyGram members gain entry to these markets via a streamlined dashboard — no coding necessary. Start trading on PolyGram →