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.
Algorithmic trading has become accessible beyond institutional finance. The Polymarket API provides developers with comprehensive access to the world's largest prediction market infrastructure. Whether you're implementing an automated rebalancing strategy or engineering a sophisticated market-making system, this resource walks through the essential components needed to begin.
API Architecture Overview
Polymarket offers two distinct API services:
- Gamma API (
gamma-api.polymarket.com): Supplies event information, market listings, condition details, and price history. Open to the public without requiring authentication - CLOB API (
clob.polymarket.com): Handles order submission, order removal, account positions, and live order book information. Requires EIP-712 signed API credentials
Authentication
CLOB API security employs a dual-layer verification system:
- L1 Authentication (EIP-712): Use your Ethereum private key to cryptographically sign a typed-data structure, generating API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Sign every request using the generated credentials. The signature incorporates the timestamp, HTTP method, endpoint path, 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 market information required for bot operation:
// 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 various order types and execution instructions:
- GTC (Good-Till-Cancelled): Remains active in the order book until manually cancelled or executed
- GTD (Good-Till-Date): Automatically expires at a predetermined timestamp
- FOK (Fill-Or-Kill): Executes completely or gets rejected entirely
- IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder
WebSocket Streaming
Connect to the CLOB WebSocket service for live market information:
// 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 involve:
- Track market prices continuously using WebSocket feeds
- Compute a moving average across a 24-hour window
- Initiate long positions when price falls 10%+ beneath the average
- Close positions when price reverts toward the average level
- Apply Kelly criterion methodology for position sizing
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 connections for live market feeds rather than repeated polling
- Store your private key within environment variables exclusively, never hardcoded
- Validate strategies using minimal capital before expanding position sizes
PolyGram users can access all these markets via an intuitive interface — API integration is completely optional. Start trading on PolyGram →