🎁 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
FIFA World Cup 2026
64%
BTC > $150k EOY 2026
38%
Fed Rate Cut Q3
47%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API lets you programmatically place orders, stream prices, and manage positions. Combined with the Gamma API for market data, you can build a fully automated prediction market trading bot.

Algorithmic trading is not restricted to institutional finance. The Polymarket API provides developers with complete access to the planet's largest prediction market ecosystem. Whether your aim is to automate a straightforward rebalancing approach or construct an advanced market-making engine, this resource walks through everything required to begin.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event information, market catalogues, condition details, and past performance metrics. Openly accessible, authentication not required
  • CLOB API (clob.polymarket.com): Order submission, removal, portfolio oversight, and live order book information. Demands EIP-712 derived API credentials

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign all API calls with the generated credentials. The signature incorporates the timestamp, HTTP verb, endpoint path, and request 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 requisite 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 several time-in-force configurations:

  • GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically terminates at a predetermined moment
  • FOK (Fill-Or-Kill): Must execute in full or be rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder

WebSocket Streaming

For live market information, establish a connection to the CLOB WebSocket interface:

// 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 engine could:

  1. Track market quotations across your chosen instruments via WebSocket
  2. Compute a moving average across the preceding 24-hour window
  3. Initiate purchases when quotations fall 10%+ beneath the moving average
  4. Close positions when quotations recover 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 information rather than repeated polling
  • Store your private key in environment settings, never hardcode it
  • Validate strategies on minimal positions prior to expansion

PolyGram users gain entry to all these markets via a streamlined dashboard — no API coding necessary. 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.