🎁 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 programmatically, monitor live price feeds, and oversee your holdings. When paired with the Gamma API for market intelligence, you gain the foundation to construct a completely autonomous prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API grants engineers unrestricted access to the planet's most active prediction market platform. Should you wish to streamline a straightforward rebalancing approach or construct an advanced market-making system, this resource walks through all essential steps to begin.

API Architecture Overview

Polymarket makes available two primary interfaces:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition specifications, and archival pricing information. Open to all, authentication not required
  • CLOB API (clob.polymarket.com): Order submission, order removal, position tracking, and live order book snapshots. Demands EIP-712 authorisation credentials

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum secret key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every request with these credentials. The signature encodes the timestamp, HTTP verb, endpoint route, 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 all necessary market information:

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

  • GTC (Good-Till-Cancelled): Remains in the book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically expires at a predetermined moment
  • FOK (Fill-Or-Kill): Executes in full or gets rejected entirely
  • IOC (Immediate-Or-Cancel): Executes partially if needed, discards unfilled remainder

WebSocket Streaming

To receive live 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 could:

  1. Track price movements across chosen markets through WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour window
  3. Initiate purchases whenever price declines 10%+ relative to this average
  4. Exit positions as price normalises toward the average level
  5. Apply Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently apply exponential backoff when receiving 429 status codes
  • Favour WebSocket connections for live feeds rather than repetitive polling
  • Safeguard your secret key within environment settings, exclude from source files
  • Validate strategies on modest volumes prior to expanding positions

PolyGram participants gain entry to these entire marketplaces via an intuitive dashboard — API coding unnecessary. 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.