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.

Priya Anand
Sports Editor — Odds & Form · 28 April 2026 · 3 min read

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 market intelligence, constructing an end-to-end automated prediction market trading bot becomes entirely feasible.

Algorithmic trading extends far beyond institutional finance desks. The Polymarket API grants developers complete programmatic access to the globe's premier prediction market platform. Whether your goal is to streamline a straightforward portfolio rebalancing approach or engineer a high-frequency market-making system, this resource walks you through all essential steps.

API Architecture Overview

Polymarket offers two principal API channels:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market definitions, outcome specifications, and time-series pricing. Open access; no sign-in credentials required
  • CLOB API (clob.polymarket.com): Order submission, removal, account holdings, and live book snapshots. Mandates EIP-712 signed API tokens

Authentication

CLOB API security employs a dual-stage verification scheme:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum account's private key to generate API tokens (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Digitally sign every call with your generated tokens. The signature encompasses the request timestamp, HTTP verb, endpoint path, and payload content

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 for your algorithms:

// 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 diverse order varieties and execution policies:

  • GTC (Good-Till-Cancelled): Remains active on the ledger until executed or withdrawn
  • GTD (Good-Till-Date): Automatically lapses at a designated moment
  • FOK (Fill-Or-Kill): Executes entirely or gets rejected outright
  • IOC (Immediate-Or-Cancel): Executes available quantity; remainder is discarded

WebSocket Streaming

To receive instantaneous market updates, establish a connection to the CLOB WebSocket gateway:

// 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 operate as follows:

  1. Track quotations across your chosen markets through WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate long positions when quotations sink 10%+ beneath the computed average
  4. Exit positions once quotations normalise toward the average level
  5. Apply Kelly criterion methodology for optimal position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Implement exponential backoff when receiving 429 status codes
  • Prefer WebSocket subscriptions over periodic polling for live feeds
  • Store your private key within environment configuration, never hardcoded
  • Validate approaches with minimal capital before expanding positions

PolyGram users gain instant entry to all these markets via an intuitive dashboard — zero coding necessary. Start trading on PolyGram →

Priya Anand
Sports Editor — Odds & Form

Priya benchmarks sports prediction-market lines against traditional sportsbooks. Specialism: Premier League, NBA, and the major European cup competitions.