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

Sarah Whitfield
Markets Editor — Political Forecasting · · 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%
Fed Rate Cut Q3
47%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables developers to submit orders programmatically, consume live price feeds, and oversee portfolio holdings. When paired with the Gamma API for market intelligence, you gain the ability to construct a completely autonomous prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API grants programmers unrestricted access to the planet's foremost prediction market infrastructure. Whether your objective is to streamline a straightforward rebalancing approach or engineer a complex market-making system, this resource walks through the entire setup process.

API Architecture Overview

Polymarket makes available two principal API surfaces:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market registries, condition hierarchies, and time-series pricing. Openly accessible, authentication unnecessary
  • CLOB API (clob.polymarket.com): Order submission, removal, portfolio tracking, and live order book snapshots. Mandates EIP-712 signed API credentials

Authentication

CLOB API security operates across two distinct tiers:

  1. L1 Authentication (EIP-712): Sign a structured-data payload using your Ethereum account's private key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign each request using the generated credentials. The signature encompasses the request timestamp, HTTP verb, endpoint path, and payload content

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 set of market intelligence required for informed trading:

// 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 diverse time-in-force configurations:

  • GTC (Good-Till-Cancelled): Remains active in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically expires upon reaching a designated timestamp
  • FOK (Fill-Or-Kill): Requires complete execution or total cancellation
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder

WebSocket Streaming

To obtain instantaneous 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

An elementary mean-reversion trading system could operate as follows:

  1. Track market quotations across your chosen venues through WebSocket feeds
  2. Determine a 24-hour rolling median price point
  3. Initiate purchases when quotation falls 10%+ beneath the computed median
  4. Liquidate holdings once quotation recovers to the median level
  5. Apply Kelly criterion methodology for optimal position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently apply exponential backoff when encountering 429 status codes
  • Favour WebSocket connections for live market feeds rather than repetitive polling
  • Store your private key within environment configuration, never embedded in source
  • Validate approaches on minimal allocations prior to production deployment

PolyGram participants can engage with these markets via a streamlined dashboard — API coding is entirely optional. Start trading on PolyGram →

Sarah Whitfield
Markets Editor — Political Forecasting

Sarah has tracked political prediction markets and election forecasting since the 2020 US cycle. Focus: US presidential, congressional, and UK parliamentary contracts.