🎁 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%
FA Cup Final
41%
Trade →

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.

Automated trading strategies are no longer confined to institutional finance. The Polymarket API grants developers unrestricted access to the planet's premier prediction market platform. From executing straightforward portfolio rebalancing to constructing an advanced market-making engine, this resource provides all the essential information required to begin.

API Architecture Overview

Polymarket makes available two primary interfaces:

  • Gamma API (gamma-api.polymarket.com): Event information, market listings, condition details, and past performance records. Openly accessible without requiring login credentials
  • CLOB API (clob.polymarket.com): Order submission, removal, portfolio oversight, and instantaneous book information. Mandates EIP-712 derived API credentials

Authentication

CLOB API security operates through a dual-layer mechanism:

  1. L1 Authentication (EIP-712): Sign a structured message using your Ethereum wallet's private key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every request with your obtained credentials. The signature incorporates 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 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 varied time-in-force settings:

  • GTC (Good-Till-Cancelled): Remains active in the book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a predetermined timestamp
  • FOK (Fill-Or-Kill): Executes entirely or gets rejected immediately
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder

WebSocket Streaming

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

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

Building a Simple Strategy

A straightforward reversion-to-mean algorithm could operate as follows:

  1. Track price movements across chosen markets using WebSocket feeds
  2. Compute a 24-hour rolling average price
  3. Initiate purchases when price falls 10%+ beneath the average
  4. Close positions when price recovers toward the 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 status codes
  • Prefer WebSocket connections for live feeds over repeated HTTP polling
  • Store your private key exclusively in environment variables, never hardcoded
  • Validate strategies with minimal capital before expanding exposure

PolyGram members gain entry to all these offerings via an intuitive dashboard — no coding necessary. 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.