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

James Carlton
Crypto Analyst — On-Chain Flows · · 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 you to submit orders programmatically, consume live price feeds, and oversee your holdings. Paired with the Gamma API for market intelligence, you can construct an end-to-end automated prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional traders. The Polymarket API provides developers with complete access to the globe's premier prediction market platform. Whether your goal is to streamline a straightforward rebalancing tactic or engineer an advanced market-making system, this resource walks you through all the essentials.

API Architecture Overview

Polymarket makes available two primary APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and time-series price information. Openly accessible without credentials
  • CLOB API (clob.polymarket.com): Order submission, removal, position tracking, and live book snapshots. Demands EIP-712 signed API credentials

Authentication

CLOB API security comprises two stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign each request using your derived credentials. The signature encodes the timestamp, HTTP 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 all the foundational information required for your trading system:

// 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 terminates at a preset moment
  • FOK (Fill-Or-Kill): Requires complete execution or immediate cancellation
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards the remainder

WebSocket Streaming

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

  1. Observe price movements across your chosen markets using WebSocket feeds
  2. Compute a trailing mean across a preceding 24-hour window
  3. Initiate a purchase when quotations fall 10%+ beneath the computed mean
  4. Exit the position once quotations recover to the mean level
  5. Apply Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Always implement exponential backoff when receiving 429 responses
  • Favour WebSocket subscriptions for live information rather than repeated polling
  • Store your private key in environment configuration, never hardcode it
  • Validate strategies with minimal capital before ramping positions

PolyGram members gain entry to these markets via a streamlined dashboard — API coding is entirely optional. Start trading on PolyGram →

James Carlton
Crypto Analyst — On-Chain Flows

James covers DeFi research and writes for PolyGram on USDC flows, the Polymarket Polygon order book, and conditional-token mechanics.