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

James Carlton
Crypto Analyst — On-Chain Flows · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
FIFA World Cup 2026
64%
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 pricing streams, and oversee your holdings. When paired with the Gamma API for market intelligence, you gain the capability to construct an end-to-end automated prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API grants engineers direct access to the globe's premier prediction market infrastructure. Whether your aim is to streamline a basic portfolio rebalancing tactic or engineer a complex market-making system, this resource walks through all essential steps for implementation.

API Architecture Overview

Polymarket makes available two principal API interfaces:

  • Gamma API (gamma-api.polymarket.com): Market specifics — competitions, trading pairs, contract states, and temporal pricing records. Publicly accessible, authentication unnecessary
  • CLOB API (clob.polymarket.com): Order submission, removal, holdings administration, and instantaneous order ledger snapshots. Mandates EIP-712 sourced API tokens

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured-data payload using your Ethereum account key to generate API tokens (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every CLOB request utilising your generated tokens. The signature encompasses the request timestamp, HTTP verb, endpoint path, and payload contents

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 catalogue and reference material:

// 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 execution orders, restricted-price orders, and varied execution duration settings:

  • GTC (Good-Till-Cancelled): Persists in the order ledger until executed or withdrawn
  • GTD (Good-Till-Date): Automatically terminates at a predetermined moment
  • FOK (Fill-Or-Kill): Requires complete execution or full cancellation
  • IOC (Immediate-Or-Cancel): Executes available quantity, terminates unfilled portion

WebSocket Streaming

To obtain live market feeds, 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

An elementary reversion-to-mean system could function as follows:

  1. Track price movements across selected markets through WebSocket connections
  2. Compute an exponential moving average spanning the preceding day
  3. Initiate long positions when quotations fall 10%+ beneath the computed average
  4. Exit positions upon price convergence with the 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
  • Always deploy exponential backoff protocols upon receiving 429 status codes
  • Favour WebSocket subscriptions for live information over repetitive polling cycles
  • Store your account key in configuration files, never hardcoded into repositories
  • Validate strategies using minimal capital prior to full-scale deployment

PolyGram participants gain entry to all these marketplaces via an intuitive dashboard — API coding entirely optional. Start trading on PolyGram →

James Carlton
Crypto Analyst — On-Chain Flows

James covers DeFi research and writes for PolyGram on USDC flows, the Polymarket Polygon order book, and conditional-token mechanics.