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

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
FIFA World Cup 2026
64%
2028 Dem Nominee
52%
Eurovision 2026 Winner
41%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders via code, consume live price feeds, and oversee your holdings. When paired with the Gamma API for market intelligence, constructing an end-to-end automated prediction market trading bot becomes straightforward.

Automated trading strategies are no longer confined to institutional finance. The Polymarket API provides developers with unrestricted access to the globe's premier prediction market ecosystem. Whether your goal is to streamline a basic portfolio rebalancing tactic or engineer an advanced market-making system, this resource equips you with all necessary knowledge to begin.

API Architecture Overview

Polymarket makes available two principal APIs:

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

Authentication

The CLOB API employs a dual-tier security model:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum account's secret key to generate authorisation parameters (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Affix a cryptographic signature to every request using your generated parameters. This signature incorporates the request's temporal marker, verb, endpoint, 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 furnishes comprehensive market intelligence for your applications:

// 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 parameters:

  • GTC (Good-Till-Cancelled): Persists in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically terminates at a predetermined moment
  • FOK (Fill-Or-Kill): Executes in full or not at all
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder

WebSocket Streaming

To obtain instantaneous market information, establish a connection to the CLOB WebSocket channel:

// 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 might incorporate these steps:

  1. Track price movements across designated markets using WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate a purchase when the price declines by 10% or more relative to the average
  4. Exit the position once the price recovers toward the average level
  5. Employ Kelly criterion methodology for determining stake magnitudes

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently employ exponential backoff when encountering 429 status codes
  • Prioritise WebSocket connections for live market data rather than repeated polling cycles
  • Store your account's secret key within environment configuration, never hardcoded in source files
  • Validate strategies using minimal capital before expanding to larger positions

PolyGram users gain access to these entire market ecosystems via an intuitive dashboard — coding expertise remains 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.