🎁 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, monitor live pricing, and control your holdings. When paired with the Gamma API for market intelligence, you can construct a completely autonomous prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional firms. The Polymarket API grants engineers direct access to the planet's foremost prediction market infrastructure. Whether your goal is to streamline a basic rebalancing approach or engineer an advanced market-making system, this resource walks you through all the essentials.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, contract specifications, and past performance records. Open to the public with no login required
  • CLOB API (clob.polymarket.com): Submission and withdrawal of orders, position tracking, and live order book snapshots. Demands EIP-712 authorisation credentials

Authentication

CLOB API security operates across two tiers:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum key to produce API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every API call with your derived credentials. The signature incorporates the timestamp, HTTP verb, endpoint path, and request 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 all essential 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 instant fills, pegged orders, and varied execution modes:

  • GTC (Good-Till-Cancelled): Persists within the order book until matched or withdrawn
  • GTD (Good-Till-Date): Automatically lapses at a designated moment
  • FOK (Fill-Or-Kill): Executes entirely or rejects outright
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder

WebSocket Streaming

To receive live market signals, 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 reversion-to-mean bot could operate as follows:

  1. Track price movements across chosen markets using WebSocket feeds
  2. Compute a 24-hour moving average
  3. Enter long positions when price falls 10%+ beneath the average
  4. Exit when price converges back to the average
  5. Apply Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Always deploy exponential backoff logic when receiving 429 status codes
  • Favour WebSocket subscriptions over repetitive polling for live feeds
  • Store your private key in environment variables, not hardcoded
  • Validate strategies with modest capital before expanding exposure

PolyGram members gain entry to all these markets via an intuitive dashboard — API coding is unnecessary. 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.