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

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
Champions League 2025/26
22%
FIFA World Cup 2026
18%
Euro 2028 Winner
12%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing feeds, and handle your portfolio holdings. When paired with the Gamma API for accessing market information, you can construct a completely autonomous prediction market trading bot.

Algorithmic trading extends well beyond institutional finance. The Polymarket API provides developers with unrestricted entry to the planet's most active prediction market. Whether your goal is to streamline a straightforward rebalancing approach or develop an advanced market-making system, this resource walks through all the essentials required to begin.

API Architecture Overview

Polymarket makes available two primary APIs:

  • Gamma API (gamma-api.polymarket.com): Event and market information — listings, specifications, conditions, and past performance records. Openly accessible, authentication not required
  • CLOB API (clob.polymarket.com): Submitting and withdrawing orders, portfolio tracking, and instantaneous order book information. Demands EIP-712 generated API tokens

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Cryptographically sign a message structure using your Ethereum wallet's private key to generate API tokens (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Digitally sign all API calls using the generated tokens. The signature encompasses the request timestamp, HTTP verb, endpoint, 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 complete set of market information required:

// 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 immediate execution, limit pricing, and various expiration strategies:

  • GTC (Good-Till-Cancelled): Remains active in the order book until matched or removed
  • GTD (Good-Till-Date): Automatically cancels at a predetermined moment
  • FOK (Fill-Or-Kill): Executes entirely or gets rejected outright
  • IOC (Immediate-Or-Cancel): Executes partially and discards unfilled portions

WebSocket Streaming

To obtain instantaneous market information, establish a connection to the CLOB WebSocket interface:

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

Building a Simple Strategy

A straightforward reversal-to-mean approach could operate as follows:

  1. Track pricing movements across chosen markets using WebSocket feeds
  2. Determine an exponential moving average across the preceding 24-hour window
  3. Initiate a purchase when quotations fall 10%+ beneath the moving average
  4. Close the position when quotations recover to the moving average
  5. Apply Kelly criterion methodology for optimal 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
  • Leverage WebSocket connections for live information rather than repeated polling
  • Store your private key in environment configuration files, never hardcoded
  • Begin with minimal stake amounts before expanding your deployment

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