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

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
BTC > $150k EOY 2026
38%
Eurovision 2026 Winner
41%
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 portfolio. When paired with the Gamma API for market intelligence, you gain the ability to construct an end-to-end automated prediction market trading system.

Algorithmic trading has transcended institutional finance. The Polymarket API grants engineers direct access to the globe's premier prediction market ecosystem. Whether your goal is automating a straightforward portfolio rebalancing approach or engineering a complex market-making engine, this resource walks you through the essentials needed to launch your project.

API Architecture Overview

Polymarket makes available two principal API layers:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition hierarchies, and past performance records. Open access, no credentials required
  • CLOB API (clob.polymarket.com): Order submission, removal, portfolio tracking, and live order book snapshots. Demands EIP-712 authorisation tokens

Authentication

CLOB API security operates across two tiers:

  1. L1 Authentication (EIP-712): Sign a structured message using your Ethereum account's private key to generate API tokens (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every request using your generated tokens. 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 dataset required for market intelligence:

// 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 execution directives:

  • GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically expires after a designated moment
  • FOK (Fill-Or-Kill): Executes in full or not at all
  • IOC (Immediate-Or-Cancel): Executes available volume, discards unmatched remainder

WebSocket Streaming

To obtain live market signals, 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 your chosen markets through WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate purchases when quoted prices fall 10%+ beneath the calculated average
  4. Exit positions once prices stabilise near the average level
  5. Employ Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Implement exponential backoff handling when receiving 429 status codes
  • Favour WebSocket connections for live market data rather than repeated polling cycles
  • Store your private key within environment configuration, never hardcoded
  • Validate strategies using minimal capital before expanding exposure

PolyGram users can engage with all these markets via a streamlined dashboard — API integration is entirely optional. 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.