In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API lets you programmatically place orders, stream prices, and manage positions. Combined with the Gamma API for market data, you can build a fully automated prediction market trading bot.
Automated trading strategies are no longer confined to institutional finance. The Polymarket API grants developers unrestricted access to the planet's premier prediction market platform. From executing straightforward portfolio rebalancing to constructing an advanced market-making engine, this resource provides all the essential information required to begin.
API Architecture Overview
Polymarket makes available two primary interfaces:
- Gamma API (
gamma-api.polymarket.com): Event information, market listings, condition details, and past performance records. Openly accessible without requiring login credentials - CLOB API (
clob.polymarket.com): Order submission, removal, portfolio oversight, and instantaneous book information. Mandates EIP-712 derived API credentials
Authentication
CLOB API security operates through a dual-layer mechanism:
- L1 Authentication (EIP-712): Sign a structured message using your Ethereum wallet's private key to obtain API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every request with your obtained 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 supplies all requisite market information:
// 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 settings:
- GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
- GTD (Good-Till-Date): Automatically cancels at a predetermined timestamp
- FOK (Fill-Or-Kill): Executes entirely or gets rejected immediately
- IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder
WebSocket Streaming
To obtain live market information, 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 reversion-to-mean algorithm could operate as follows:
- Track price movements across chosen markets using WebSocket feeds
- Compute a 24-hour rolling average price
- Initiate purchases when price falls 10%+ beneath the average
- Close positions when price recovers toward the average
- Apply Kelly criterion methodology for optimal position sizing
Rate Limits and Best Practices
- CLOB API: 100 requests per 10 seconds per API key
- Implement exponential backoff when receiving 429 status codes
- Prefer WebSocket connections for live feeds over repeated HTTP polling
- Store your private key exclusively in environment variables, never hardcoded
- Validate strategies with minimal capital before expanding exposure
PolyGram members gain entry to all these offerings via an intuitive dashboard — no coding necessary. Start trading on PolyGram →