Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing, and oversee your holdings. When paired with the Gamma API for market intelligence, you can construct an entirely autonomous prediction market trading bot.
Automated trading strategies aren't confined to institutional finance. The Polymarket API grants developers unrestricted access to the globe's premier prediction market platform. If your goal is to streamline a basic rebalancing approach or engineer an advanced market-making system, this resource provides all the essentials for launching your project.
API Architecture Overview
Polymarket makes available two principal APIs:
- Gamma API (
gamma-api.polymarket.com): Event information, market listings, condition details, and past performance metrics. Openly accessible, no login required - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio administration, and live order book snapshots. Demands EIP-712 derived API credentials
Authentication
CLOB API security operates across two distinct stages:
- L1 Authentication (EIP-712): Cryptographically sign a structured-data payload using your Ethereum private key to produce API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Cryptographically sign all API communications using the generated 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 furnishes comprehensive market information you'll require:
// 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 several execution timing choices:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
- GTD (Good-Till-Date): Automatically lapses at a predetermined moment
- FOK (Fill-Or-Kill): Executes in full or gets discarded entirely
- IOC (Immediate-Or-Cancel): Executes available quantity, discards unfilled balance
WebSocket Streaming
To obtain instantaneous 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 could operate as follows:
- Track pricing movements across your chosen markets using WebSocket feeds
- Compute a moving average spanning the preceding 24-hour window
- Initiate purchases when quotations fall 10%+ beneath this threshold
- Close positions when quotations revert toward the baseline
- Employ Kelly criterion methodology for stake determination
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Consistently apply exponential backoff when encountering 429 status codes
- Leverage WebSocket connections for live information rather than repeated polling
- Safeguard your private key within environment configuration, away from source files
- Validate approaches using modest capital before expanding positions
PolyGram participants gain entry to all these markets via an intuitive platform — coding expertise unnecessary. Start trading on PolyGram →