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

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%
Eurovision 2026 Winner
41%
ETH > $8k EOY
33%
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.

Automated trading strategies are no longer confined to institutional finance. The Polymarket API opens programmatic access to the globe's premier prediction market platform. Whether your goal is to execute an automated rebalancing approach or construct an advanced market-making system, this resource walks you through the entire setup process.

API Architecture Overview

Polymarket offers two distinct API layers:

  • Gamma API (gamma-api.polymarket.com): Supplies market information — events, conditions, markets, and time-series pricing. Publicly accessible without requiring credentials
  • CLOB API (clob.polymarket.com): Handles order submission, removal, account management, and live order book snapshots. Requires EIP-712 signed API credentials

Authentication

The CLOB API employs a dual-layer security model:

  1. L1 Authentication (EIP-712): Use your Ethereum private key to sign a structured message, generating API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every request using the generated credentials. The signature includes the request timestamp, HTTP method, endpoint path, 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 essential market information required for your trading logic:

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

  • GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically expires at a designated timestamp
  • FOK (Fill-Or-Kill): Either executes in full or is rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards the remainder

WebSocket Streaming

To receive live updates, 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 would operate as follows:

  1. Track price movements across chosen markets using WebSocket feeds
  2. Compute a 24-hour moving average
  3. Initiate a purchase when price falls 10%+ beneath the average
  4. Exit the position once price recovers to the average level
  5. Apply Kelly criterion methodology for position sizing

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Implement exponential backoff when receiving 429 rate-limit responses
  • Prefer WebSocket subscriptions over repeated polling for live information
  • Store your private key in environment variables exclusively, never hardcode it
  • Validate strategies with minimal capital before expanding position sizes

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