Skip to main content
HomeBlog › Prediction Market API: Build Your Own Trading Bot
Prediction

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.

Marc Jakob
Senior Editor — Prediction Markets · 28 April 2026 · 3 min read

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.

Algorithmic trading extends far beyond institutional finance desks. The Polymarket API provides developers with comprehensive access to the globe's premier prediction market platform. Whether your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making bot, this resource walks you through every essential step.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event information, market listings, condition details, and past performance records. Publicly accessible without login credentials
  • CLOB API (clob.polymarket.com): Order submission, removal, position tracking, and live order book information. Demands EIP-712 derived API credentials

Authentication

CLOB API security employs a dual-layer approach:

  1. L1 Authentication (EIP-712): Sign a structured data message using your Ethereum private key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every API call using the obtained credentials. The signature includes the request timestamp, HTTP verb, 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 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 various execution instructions:

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

WebSocket Streaming

To obtain live information, establish a connection to the CLOB WebSocket service:

// 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 using WebSocket feeds
  2. Compute a moving average spanning the preceding day
  3. Initiate purchases when price declines 10%+ relative to the moving average
  4. Exit positions once price recovers to the moving 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
  • Always implement exponential backoff on 429 responses
  • Use WebSockets for real-time data instead of polling
  • Keep your private key in environment variables, never in code
  • Test on small positions before scaling up

PolyGram users can access all these markets through a simplified interface — no API development required. Start trading on PolyGram →

Marc Jakob
Senior Editor — Prediction Markets

Marc has covered prediction markets and crypto order flow since 2018. Writes for PolyGram on market structure, on-chain settlement, and regulatory developments.