In this guide
Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing feeds, and handle your portfolio holdings. When paired with the Gamma API for accessing market information, you can construct a completely autonomous prediction market trading bot.
Algorithmic trading extends well beyond institutional finance. The Polymarket API provides developers with unrestricted entry to the planet's most active prediction market. Whether your goal is to streamline a straightforward rebalancing approach or develop an advanced market-making system, this resource walks through all the essentials required to begin.
API Architecture Overview
Polymarket makes available two primary APIs:
- Gamma API (
gamma-api.polymarket.com): Event and market information — listings, specifications, conditions, and past performance records. Openly accessible, authentication not required - CLOB API (
clob.polymarket.com): Submitting and withdrawing orders, portfolio tracking, and instantaneous order book information. Demands EIP-712 generated API tokens
Authentication
CLOB API security operates across two distinct stages:
- L1 Authentication (EIP-712): Cryptographically sign a message structure using your Ethereum wallet's private key to generate API tokens (apiKey, secret, passphrase)
- L2 Authentication (HMAC-SHA256): Digitally sign all API calls using the generated tokens. The signature encompasses the request timestamp, HTTP verb, endpoint, 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 complete set of market information required:
// 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 immediate execution, limit pricing, and various expiration strategies:
- GTC (Good-Till-Cancelled): Remains active in the order book until matched or removed
- GTD (Good-Till-Date): Automatically cancels at a predetermined moment
- FOK (Fill-Or-Kill): Executes entirely or gets rejected outright
- IOC (Immediate-Or-Cancel): Executes partially and discards unfilled portions
WebSocket Streaming
To obtain instantaneous market information, establish a connection to the CLOB WebSocket interface:
// Subscribe to order book updates
ws.send(JSON.stringify({
type: "subscribe",
channel: "market",
assets_id: TOKEN_ID
}));
Building a Simple Strategy
A straightforward reversal-to-mean approach could operate as follows:
- Track pricing movements across chosen markets using WebSocket feeds
- Determine an exponential moving average across the preceding 24-hour window
- Initiate a purchase when quotations fall 10%+ beneath the moving average
- Close the position when quotations recover to the moving 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 rate-limit responses
- Leverage WebSocket connections for live information rather than repeated polling
- Store your private key in environment configuration files, never hardcoded
- Begin with minimal stake amounts before expanding your deployment
PolyGram members gain entry to all these markets via a streamlined dashboard — no programming expertise needed. Start trading on PolyGram →