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

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
2028 Dem Nominee
52%
Fed Rate Cut Q3
47%
ETH > $8k EOY
33%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API lets you programmatically place orders, stream prices, and manage positions. Combined with the Gamma API for market data, you can build a fully automated prediction market trading bot.

Algorithmic trading extends far beyond institutional finance. The Polymarket API provides developers with comprehensive access to the globe's foremost prediction market platform. From automating straightforward portfolio adjustments to constructing advanced market-making systems, this resource outlines the foundational steps required for implementation.

API Architecture Overview

Polymarket makes available two distinct API services:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market specifications, condition identifiers, and archival pricing information. Publicly accessible without credentials
  • CLOB API (clob.polymarket.com): Order submission, withdrawal, position tracking, and live order book snapshots. Demands EIP-712 authorisation credentials

Authentication

CLOB API authorisation operates across two distinct phases:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum keypair to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign each request using the obtained credentials. The signature encompasses 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 comprehensive market information required for bot operation:

// 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 various order classifications and temporal constraints:

  • GTC (Good-Till-Cancelled): Persists within the order book until execution or withdrawal
  • GTD (Good-Till-Date): Automatically cancels upon reaching a designated timestamp
  • FOK (Fill-Or-Kill): Executes entirely or rejects entirely without partial fills
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder

WebSocket Streaming

For instantaneous market information, establish a connection to the CLOB WebSocket service:

// 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 system would typically:

  1. Track market quotations across designated contracts through WebSocket feeds
  2. Determine a moving average across the preceding 24-hour window
  3. Initiate long positions when quotations fall 10%+ beneath the moving average
  4. Exit positions once quotations normalise toward the moving average
  5. Apply Kelly criterion methodology for position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Implement exponential backoff procedures when receiving 429 status codes
  • Prioritise WebSocket subscriptions for live market feeds rather than repetitive polling cycles
  • Store your private key within environment configuration, never embedded within application code
  • Validate strategies using minimal capital before expanding position sizes

PolyGram participants gain streamlined access to these markets via an intuitive trading platform — technical API integration 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.