🎁 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, monitor live price feeds, and oversee your portfolio. When paired with the Gamma API for market intelligence, you can construct a completely autonomous prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API grants engineers direct access to the planet's foremost prediction market ecosystem. Whether your goal is to streamline a straightforward rebalancing workflow or develop an advanced market-making system, this resource walks 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, condition identifiers, and archival pricing information. Publicly accessible, no credentials required
  • CLOB API (clob.polymarket.com): Order submission, withdrawal, portfolio tracking, and live order book snapshots. Demands EIP-712 authorisation credentials

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured data object using your Ethereum keypair to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign each request using your derived credentials. The signature incorporates the request timestamp, HTTP verb, resource 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 market information your application requires:

// 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 both market and limit order types, along with varied execution instructions:

  • GTC (Good-Till-Cancelled): Persists within the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically expires upon reaching a designated timestamp
  • FOK (Fill-Or-Kill): Executes entirely or rejects entirely with no partial fills
  • IOC (Immediate-Or-Cancel): Executes available quantity and rejects unmatched volume

WebSocket Streaming

To receive instantaneous market information, establish a connection to the CLOB WebSocket gateway:

// Subscribe to order book updates
ws.send(JSON.stringify({
  type: "subscribe",
  channel: "market",
  assets_id: TOKEN_ID
}));

Building a Simple Strategy

A fundamental mean-reversion approach could operate as follows:

  1. Track market valuations across your chosen set via WebSocket feeds
  2. Compute a trailing average spanning the preceding 24-hour window
  3. Initiate purchases when valuations fall 10%+ beneath the trailing average
  4. Exit positions once valuations recover to the trailing average 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 employ exponential backoff when receiving 429 status codes
  • Favour WebSocket subscriptions for live market feeds rather than repeated polling
  • Store your private key within environment configuration, never embedded in source files
  • Validate strategies using minimal capital before expanding to larger allocations

PolyGram members gain access to these entire market catalogues via an intuitive dashboard — no coding expertise needed. 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.