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

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%
2028 Dem Nominee
52%
ETH > $8k EOY
33%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor 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 access to the planet's foremost prediction market. Whether your aim is to streamline a straightforward rebalancing tactic or develop an advanced market-making engine, this resource walks you through everything required to begin.

API Architecture Overview

Polymarket makes available two primary APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and archival price information. Openly accessible, no authorisation required
  • CLOB API (clob.polymarket.com): Order submission, removal, portfolio oversight, and instantaneous order book visibility. Mandates EIP-712 derived API credentials

Authentication

CLOB API security employs a dual-stage mechanism:

  1. L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum account's secret key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every API call with the obtained credentials. The signature incorporates the request's timestamp, 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 supplies the complete market information your bot requires:

// 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 facilitates market orders, limit orders, and varied time-in-force configurations:

  • GTC (Good-Till-Cancelled): Remains on the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a predetermined moment
  • FOK (Fill-Or-Kill): Executes entirely or rejects entirely
  • IOC (Immediate-Or-Cancel): Executes partially if necessary, discards unfilled portions

WebSocket Streaming

To receive instantaneous updates, establish a connection 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 reversion-to-mean bot could operate as follows:

  1. Observe price movements across designated markets using WebSocket feeds
  2. Compute a moving average spanning the preceding 24-hour interval
  3. Initiate buys when price declines 10%+ relative to the average
  4. Close positions when price recovers toward the average
  5. Employ Kelly criterion for optimal position sizing

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently employ exponential backoff when encountering 429 responses
  • Favour WebSockets for live market data over repeated polling
  • Store your secret key in configuration files, never hardcoded
  • Validate strategies with minimal capital before expanding positions

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