🎁 New traders: 100% Deposit Match up to $500 · 0% fees · instant USDC payoutsClaim it →
Skip to main content
HomeBlog › Prediction Market API: Build Your Own Trading Bot
Politics

Prediction Market API: Build Your Own Trading Bot

How to build a prediction market trading bot using the Polymarket CLOB API. Code examples, authentication, order placement, and strategy automation.

Sarah Whitfield
Markets Editor — Political Forecasting · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
Trump Impeachment 2027
14%
UK PM by 2026
48%
Iran Peace Deal 2026
6%
Trade →

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 market intelligence, you gain the tools to construct an entirely autonomous prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API grants developers unrestricted entry to the globe's premier prediction market platform. Whether your objective is to streamline a basic portfolio rebalancing approach or construct an advanced market-making bot, this resource covers all essential information required to begin.

API Architecture Overview

Polymarket makes available two distinct APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition specifications, and archival pricing information. Publicly accessible, authentication not required
  • CLOB API (clob.polymarket.com): Order submission, removal, holding oversight, and instantaneous order book snapshots. Demands EIP-712 derived API credentials

Authentication

CLOB API security comprises two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every API call using the generated credentials. The signature incorporates the request timestamp, HTTP verb, endpoint path, 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 delivers comprehensive 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 numerous time-in-force configurations:

  • GTC (Good-Till-Cancelled): Remains in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a predetermined moment
  • FOK (Fill-Or-Kill): Must execute in full or be rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder

WebSocket Streaming

For 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 mean-reversion algorithm might execute the following:

  1. Track price movements across designated markets through WebSocket feeds
  2. Compute a moving average across the preceding 24-hour window
  3. Initiate purchases when prices fall 10%+ beneath the moving average
  4. Exit positions once prices normalise toward the average
  5. Employ Kelly criterion methodology for position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently apply exponential backoff when receiving 429 responses
  • Favour WebSocket subscriptions over repetitive polling for live updates
  • Store your private key within environment configuration, never hardcoded
  • Validate strategies using modest capital before expanding positions

PolyGram participants can engage with all these markets via a streamlined interface — no API coding necessary. Start trading on PolyGram →

Sarah Whitfield
Markets Editor — Political Forecasting

Sarah has tracked political prediction markets and election forecasting since the 2020 US cycle. Focus: US presidential, congressional, and UK parliamentary contracts.