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.

Marc Jakob
Senior Editor — Prediction Markets · 28 April 2026 · 3 min read

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 belongs to everyone, not merely institutional investors. The Polymarket API grants developers unrestricted access to the globe's preeminent prediction market platform. Whether your aim is to streamline a straightforward rebalancing approach or construct an intricate market-making bot, this resource equips you with all essentials to begin.

API Architecture Overview

Polymarket makes available two primary APIs:

  • Gamma API (gamma-api.polymarket.com): Event information, market listings, conditions, and past performance data. Openly accessible, no login credentials required
  • CLOB API (clob.polymarket.com): Order submission, removal, holdings oversight, and live order book information. Demands EIP-712 authorised API credentials

Authentication

CLOB API authorisation operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured-data payload using your Ethereum private key to produce API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every API call utilising the generated credentials. The signature encompasses the date-time, operation type, 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 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 varied expiration approaches:

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

WebSocket Streaming

For instantaneous information, 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 reversion-to-mean algorithm could:

  1. Track quotations across designated markets through WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate a purchase when quotation declines 10%+ relative to the moving average
  4. Initiate a sale when quotation reverts to the moving average level
  5. Apply Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently employ exponential backoff when encountering 429 responses
  • Favour WebSocket connections for live information over repetitive polling
  • Store your private key within environment settings, never embedded in source files
  • Validate approaches using modest allocations prior to expanding exposure

PolyGram members gain entry to all these markets via an intuitive dashboard — no coding expertise necessary. Start trading on PolyGram →

Marc Jakob
Senior Editor — Prediction Markets

Marc has covered prediction markets and crypto order flow since 2018. Writes for PolyGram on market structure, on-chain settlement, and regulatory developments.