🎁 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%
Eurovision 2026 Winner
41%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and oversee your portfolio. When paired with the Gamma API for market intelligence, constructing an end-to-end automated prediction market trading bot becomes entirely feasible.

Automated trading strategies are no longer confined to institutional finance. The Polymarket API grants developers unrestricted entry to the planet's foremost prediction market ecosystem. Whether your goal involves automating a straightforward portfolio rebalancing tactic or engineering an advanced market-making system, this resource walks you through all essential steps to begin.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, outcome specifications, and archival pricing information. Openly accessible without requiring sign-in credentials
  • CLOB API (clob.polymarket.com): Order submission, order withdrawal, portfolio tracking, and live order book snapshots. Demands EIP-712 signed API credentials

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured message using your Ethereum account's private key to produce API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Digitally sign every request sent to the API using your derived 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 furnishes 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 varied 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 expiry moment
  • FOK (Fill-Or-Kill): Either executes in full or gets rejected entirely
  • 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 feed:

// 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. Track price movements across chosen markets through WebSocket connections
  2. Compute a moving average spanning the preceding day
  3. Initiate purchases when quotations sink 10%+ beneath the calculated average
  4. Liquidate holdings once quotations revert to the average level
  5. Employ Kelly criterion methodology for optimal position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently deploy exponential backoff logic when encountering 429 status codes
  • Favour WebSocket subscriptions over repetitive polling for live market feeds
  • Safeguard your private key within environment configuration files, excluding it from source repositories
  • Validate strategies using modest capital allocations before expanding exposure

PolyGram members gain entry to all these markets via a streamlined dashboard — API integration 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.