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 · 28 April 2026 · 3 min read

Prediction Market API: Build Your Own Trading Bot

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. The Polymarket API grants developers unrestricted access to the globe's premier prediction marketplace. If your goal is to streamline a straightforward rebalancing approach or construct an intricate market-making bot, this resource walks you through all necessary steps.

API Architecture Overview

Polymarket offers two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Market metadata — events, markets, conditions, historical data. Public, no authentication needed
  • CLOB API (clob.polymarket.com): Order placement, cancellation, position management, and real-time order book data. Requires EIP-712 derived API credentials

Authentication

CLOB API authentication employs a dual-layer mechanism:

  1. L1 Authentication (EIP-712): Sign a typed-data message with your Ethereum private key to derive API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign each API request with the derived credentials. The signature covers the timestamp, method, path, and body

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 required for your trading operations:

// 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 time-in-force configurations:

  • GTC (Good-Till-Cancelled): Sits in the order book until filled or cancelled
  • GTD (Good-Till-Date): Expires at a specified time
  • FOK (Fill-Or-Kill): Must fill completely or not at all
  • IOC (Immediate-Or-Cancel): Fills what it can, cancels the rest

WebSocket Streaming

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

// 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 bot could operate as follows:

  1. Monitor prices for a set of markets via WebSocket
  2. Calculate a rolling average over the last 24 hours
  3. Buy when price drops 10%+ below the average
  4. Sell when price returns to the average
  5. Use Kelly criterion to size positions

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 →

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.