🎁 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
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 · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
FIFA World Cup 2026
64%
Eurovision 2026 Winner
41%
Fed Rate Cut Q3
47%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing, and handle your portfolio with precision. When paired with the Gamma API for comprehensive market intelligence, you gain the tools to construct a fully autonomous prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional investors. The Polymarket API grants developers unrestricted entry to the planet's premier prediction market ecosystem. Whether your goal is to streamline a basic rebalancing approach or engineer an advanced market-making system, this resource equips you with the foundations required to begin.

API Architecture Overview

Polymarket makes available two principal API offerings:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition specifications, and archival pricing information. Openly accessible without sign-in credentials
  • CLOB API (clob.polymarket.com): Submission and withdrawal of orders, portfolio oversight, and live order book snapshots. Demands EIP-712 authenticated API keys

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum private key to produce API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Affix a cryptographic signature to every API call using your credentials. The signature encodes the moment in time, 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 the complete set of 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 a range of expiration mechanisms:

  • GTC (Good-Till-Cancelled): Remains active within the order book pending execution or manual withdrawal
  • GTD (Good-Till-Date): Automatically expires upon reaching a designated timestamp
  • FOK (Fill-Or-Kill): Executes in full or gets rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards unmatched remainder

WebSocket Streaming

To obtain instantaneous market feeds, 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 could operate as follows:

  1. Track pricing movements across your target markets through WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate a long position when price descends 10%+ beneath the computed average
  4. Exit the position once price recovers to 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
  • Consistently deploy exponential backoff logic when receiving 429 status codes
  • Leverage WebSocket connections for live feeds rather than repeated polling cycles
  • Safeguard your private key within environment configuration, not hardcoded strings
  • Validate strategies with minimal capital allocation prior to expansion

PolyGram participants gain entry to these markets via an intuitive dashboard interface — coding expertise not required. 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.