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

Marc Jakob
Senior Editor — Prediction Markets · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
2028 Dem Nominee
52%
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 price feeds, and oversee your holdings. When paired with the Gamma API for market intelligence, you gain the foundation to construct an entirely self-executing prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional finance. The Polymarket API grants engineers unrestricted access to the planet's most active prediction market. Whether your aim is to streamline a basic rebalancing workflow or engineer a cutting-edge market-making system, this resource walks you through all the essentials.

API Architecture Overview

Polymarket makes available two primary interfaces:

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

Authentication

CLOB API security operates across two tiers:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum secret key to produce 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 supplies the complete set of market information your bot requires:

// 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 diverse time-in-force configurations:

  • GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a predetermined moment
  • FOK (Fill-Or-Kill): Executes in full or gets rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards unfilled portion

WebSocket Streaming

To obtain instantaneous 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 mean-reversion approach would:

  1. Track price movements across chosen markets using WebSocket feeds
  2. Compute a moving average spanning the preceding day
  3. Initiate a purchase when price falls 10%+ beneath the average
  4. Exit the position once price normalises toward the average
  5. Apply Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Always implement exponential backoff on 429 responses
  • Leverage WebSockets for live information rather than continuous polling
  • Store your secret key in environment variables, never hardcoded
  • Validate strategies on minimal capital before increasing exposure

PolyGram participants gain entry to all these markets via an intuitive dashboard — API coding is completely optional. 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.