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

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
Eurovision 2026 Winner
41%
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 streams, and oversee your holdings. When paired with the Gamma API for market intelligence, you can construct an end-to-end automated prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API provides developers with unrestricted access to the planet's leading prediction market. If your goal is to streamline a straightforward rebalancing tactic or engineer an advanced market-making bot, this resource walks you through all the essentials.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and archival pricing. Open to the public with no sign-in requirement
  • CLOB API (clob.polymarket.com): Order submission, removal, position tracking, and live order book snapshots. Mandates EIP-712 authorised API keys

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 API call using the generated credentials. The signature encodes 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 required:

// 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 varied time-in-force specifications:

  • GTC (Good-Till-Cancelled): Remains in the book until executed or withdrawn
  • GTD (Good-Till-Date): Lapses at a predetermined moment
  • FOK (Fill-Or-Kill): Executes entirely or gets rejected outright
  • IOC (Immediate-Or-Cancel): Executes available volume, discards the balance

WebSocket Streaming

To obtain instantaneous information, establish a link 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 approach could:

  1. Track price movements across chosen markets using WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate purchases when the price falls 10%+ beneath the moving average
  4. Liquidate holdings once price recovers to the moving average level
  5. Apply Kelly criterion methodology for position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Always implement exponential backoff on 429 responses
  • Favour WebSockets for live feeds rather than continuous polling
  • Safeguard your secret key using environment configuration, never hardcode it
  • Validate strategies with modest stakes before ramping exposure

PolyGram members gain entry to all these markets via a streamlined dashboard — API coding is entirely 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.