🎁 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 portfolio holdings. When paired with the Gamma API for market intelligence, you can construct an entirely automated prediction market trading bot.

Algorithmic trading extends far beyond institutional finance. The Polymarket API grants engineers direct access to the globe's most active prediction marketplace. Whether your goal is to automate a straightforward rebalancing approach or engineer a complex market-making system, this resource walks through all the essentials needed to launch your project.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition specifications, and archived pricing information. Openly accessible, authentication not required
  • CLOB API (clob.polymarket.com): Order submission, removal, asset allocation oversight, and live order book information. Mandates EIP-712 authorisation credentials

Authentication

CLOB API security operates across two distinct tiers:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message utilising your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign all API communications using the generated credentials. The signature encompasses the timestamp, HTTP method, 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 furnishes all requisite market intelligence:

// 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): Persists within the order book until execution or withdrawal
  • GTD (Good-Till-Date): Automatically cancels at a predetermined moment
  • FOK (Fill-Or-Kill): Executes in full or terminates entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity, terminates unmatched portion

WebSocket Streaming

To receive instantaneous market updates, 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 mean-reversion approach could operate as follows:

  1. Track pricing movements across designated markets through WebSocket feeds
  2. Determine a moving average spanning the preceding 24-hour window
  3. Initiate purchases when quotations fall 10%+ beneath this threshold
  4. Close positions upon price normalisation back towards the average
  5. Apply Kelly criterion methodology for optimal position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently apply exponential backoff when encountering 429 status codes
  • Leverage WebSockets for live information feeds rather than continuous polling
  • Store your private key within environment configuration, never hardcode it
  • Validate strategies on modest volumes prior to expanding positions

PolyGram participants gain entry to all these marketplaces via an intuitive dashboard — API coding is entirely optional. 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.