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

Priya Anand
Sports Editor — Odds & Form · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
FIFA World Cup 2026
64%
BTC > $150k EOY 2026
38%
ETH > $8k EOY
33%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing streams, and oversee your holdings. When paired with the Gamma API for market intelligence, constructing an end-to-end automated prediction market trading bot becomes straightforward.

Algorithmic trading extends far beyond institutional finance desks. The Polymarket API provides developers with unrestricted entry to the planet's most active prediction market ecosystem. Whether your objective is to streamline a basic portfolio rebalancing workflow or engineer a complex market-making system, this resource walks you through all essential steps.

API Architecture Overview

Polymarket makes available two principal interfaces:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition definitions, and archival pricing information. Publicly accessible without credentials
  • CLOB API (clob.polymarket.com): Order submission, order removal, position tracking, and live order book snapshots. Mandates EIP-712 authorised credentials

Authentication

CLOB API security operates across two distinct layers:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every request using the generated 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 intelligence required 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 market orders, limit orders, and various time-in-force configurations:

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

WebSocket Streaming

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

  1. Observe price movements across selected markets through WebSocket feeds
  2. Determine a moving average spanning the preceding twenty-four-hour window
  3. Initiate purchases when quotations fall ten percent or greater beneath this benchmark
  4. Initiate sales once quotations recover to the benchmark 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
  • Consistently employ exponential backoff when receiving 429 status codes
  • Leverage WebSocket connections for live market data rather than repetitive polling
  • Safeguard your private key within environment configuration files, never hardcode it
  • Validate strategies using minimal capital before expanding exposure

PolyGram participants gain entry to all these marketplaces via an intuitive dashboard — API development unnecessary. 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.