🎁 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
Prediction

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
Eurovision 2026 Winner
41%
Fed Rate Cut Q3
47%
ETH > $8k EOY
33%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and oversee your holdings. When paired with the Gamma API for retrieving market information, you gain the capability to construct an entirely automated prediction market trading bot.

Automated trading strategies are no longer confined to institutional finance. The Polymarket API grants developers unrestricted access to the planet's premier prediction market infrastructure. Whether your goal is to automate routine portfolio rebalancing or engineer a cutting-edge market-making engine, this resource walks through all essential steps.

API Architecture Overview

Polymarket makes available two primary interfaces:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and time-series pricing. Open access, authentication not required
  • CLOB API (clob.polymarket.com): Order submission, order removal, asset tracking, and live order book snapshots. Demands EIP-712 signed API keys

Authentication

CLOB API security operates in two stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum keypair to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every request using your generated credentials. The signature includes 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 furnishes all requisite 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 various time-in-force configurations:

  • GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a predetermined timestamp
  • FOK (Fill-Or-Kill): Executes in full or not executed at all
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards unfilled portion

WebSocket Streaming

For live market information, establish a connection to the CLOB WebSocket feed:

// 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:

  1. Track pricing movements across target markets through WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour period
  3. Enter long positions when quotations fall 10%+ beneath the calculated average
  4. Exit when quotations recover to the average level
  5. Apply Kelly criterion methodology for position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Always implement exponential backoff when receiving 429 status codes
  • Prioritise WebSocket connections for time-sensitive data rather than repeated HTTP polling
  • Store your private key in environment variables, never hardcode it
  • Validate strategies on minimal positions prior to expanding capital allocation

PolyGram users gain entry to all these markets via a streamlined 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.