In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live price feeds, and oversee your holdings. When paired with the Gamma API for retrieving market information, you can construct an entirely self-executing prediction market trading bot.
Automated trading strategies are no longer confined to institutional finance. The Polymarket API grants programmers direct access to the planet's foremost prediction market. Whether your goal is to streamline a basic portfolio rebalancing approach or develop an advanced market-making bot, this resource walks you through all essential steps.
API Architecture Overview
Polymarket makes available two primary APIs:
- Gamma API (
gamma-api.polymarket.com): Event listings, market catalogues, condition identifiers, and archival pricing information. Open to the public with no credentials required - CLOB API (
clob.polymarket.com): Submitting and withdrawing orders, position tracking, and live order book snapshots. Mandates EIP-712 authorisation credentials
Authentication
Access to the CLOB API involves a dual-layer verification process:
- L1 Authentication (EIP-712): Use your Ethereum private key to sign a structured data object, generating your API credentials (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Each request to the API must be signed using your 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 supplies the complete set of market information required for your application:
// 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 several order varieties and expiration behaviours:
- GTC (Good-Till-Cancelled): Remains active in the order book until executed or manually removed
- GTD (Good-Till-Date): Automatically expires upon reaching a designated moment
- FOK (Fill-Or-Kill): Either executes in full immediately or is discarded entirely
- IOC (Immediate-Or-Cancel): Fulfils any available quantity and discards unfilled remainder
WebSocket Streaming
To obtain instantaneous market information, establish a connection to the CLOB WebSocket service:
// Subscribe to order book updates
ws.send(JSON.stringify({
type: "subscribe",
channel: "market",
assets_id: TOKEN_ID
}));
Building a Simple Strategy
An elementary reversal-to-mean bot could operate as follows:
- Track price movements across chosen markets using WebSocket feeds
- Determine an exponential moving average spanning the preceding 24-hour window
- Initiate a purchase position when price declines 10%+ relative to that average
- Close the position when price recovers toward 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
- Incorporate exponential backoff logic when receiving 429 status codes
- Prioritise WebSocket connections for live data instead of repeated polling cycles
- Store your private key exclusively in environment configuration, never hardcoded
- Validate strategies using minimal capital before expanding to larger amounts
PolyGram participants gain entry to all these markets via a streamlined dashboard — API programming is entirely optional. Start trading on PolyGram →