🎁 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
Premier League Champion
64%
Euro 2028 Winner
12%
Top Scorer 2025/26
33%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live price feeds, and oversee your holdings. When paired with the Gamma API for event and market intelligence, you can construct an entirely self-executing prediction market trading bot.

Automated trading strategies are no longer confined to institutional finance. The Polymarket API grants developers unrestricted entry to the planet's premier prediction market platform. Whether your goal is to streamline a basic portfolio adjustment tactic or engineer an advanced market-making system, this resource covers all the essentials for getting up and running.

API Architecture Overview

Polymarket offers two distinct API layers:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition details, and price history. Freely accessible without credential requirements
  • CLOB API (clob.polymarket.com): Order submission, order removal, portfolio tracking, and live order book snapshots. Demands EIP-712 signed API credentials

Authentication

CLOB API security operates across two distinct tiers:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured data payload using your Ethereum secret key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Digitally sign every request dispatched to the API. 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 the complete information landscape required for market analysis:

// 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, price-restricted orders, and various expiration policies:

  • GTC (Good-Till-Cancelled): Remains active in the order book until you execute or withdraw it
  • GTD (Good-Till-Date): Automatically expires on your chosen date
  • FOK (Fill-Or-Kill): Executes in full or gets rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder

WebSocket Streaming

For instantaneous market information, establish a connection to the CLOB WebSocket feed:

// 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 quotations across your target markets through WebSocket feeds
  2. Determine a moving average based on the preceding day's activity
  3. Initiate purchases when quotations sink 10%+ beneath the moving average
  4. Exit positions once quotations recover to the moving average level
  5. Employ Kelly criterion methodology for optimal position sizing

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Consistently apply exponential backoff logic when encountering 429 status codes
  • Leverage WebSocket connections for live market data rather than continuous polling
  • Safeguard your secret key through environment variable storage, never hardcode it
  • Validate strategies with minimal capital allocation before expanding volume

PolyGram participants gain entry to all these markets via a streamlined dashboard — API coding is entirely optional. 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.