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

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
SOL > $400 EOY
22%
USDC > USDT Mkt Cap
19%
Fed Cuts Rates Q3
47%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and handle your portfolio. Paired with the Gamma API for market intelligence, you can construct a fully autonomous prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional traders. The Polymarket API grants developers unrestricted entry to the globe's premier prediction market. If your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making engine, this resource walks you through all the essentials.

API Architecture Overview

Polymarket offers two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Marketplace information — contests, trading pairs, event specifications, and archival records. Openly accessible, no credentials required
  • CLOB API (clob.polymarket.com): Order submission, removal, holdings oversight, and instantaneous book snapshots. Demands EIP-712 derived API credentials

Authentication

CLOB API verification employs a dual-tier mechanism:

  1. L1 Authentication (EIP-712): Create a signed typed-data payload using your Ethereum account's secret key to produce API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Append a cryptographic signature to each call leveraging your derived credentials. The signature incorporates the moment in time, HTTP verb, endpoint, and request 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 marketplace information required for your bot:

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

  • 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 entirely or gets rejected outright
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards unmatched portion

WebSocket Streaming

To obtain live 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

A straightforward mean-reversion approach could operate as follows:

  1. Observe price movements across chosen markets using WebSocket feeds
  2. Determine an exponential moving average spanning the preceding day
  3. Initiate purchases when quotations sink 10%+ beneath the average
  4. Liquidate holdings once quotations recover to baseline
  5. Employ Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 calls per 10 seconds per credential set
  • Consistently apply exponential backoff when receiving 429 status codes
  • Favour WebSocket subscriptions for live information rather than continuous polling
  • Safeguard your secret key within configuration files, away from repositories
  • Validate approaches with minimal capital prior to expansion

PolyGram members gain entry to every crypto market through a streamlined dashboard — zero coding effort needed. 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.