🎁 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
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 · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
FIFA World Cup 2026
64%
BTC > $150k EOY 2026
38%
Eurovision 2026 Winner
41%
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 retrieving market information, 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 programmers direct access to the planet's foremost prediction market. Whether your goal is to streamline a basic portfolio rebalancing approach or develop an advanced market-making bot, this resource walks you through all essential steps.

API Architecture Overview

Polymarket makes available two primary APIs:

  • Gamma API (gamma-api.polymarket.com): Event listings, market catalogues, condition identifiers, and archival pricing information. Open to the public with no credentials required
  • CLOB API (clob.polymarket.com): Submitting and withdrawing orders, position tracking, and live order book snapshots. Mandates EIP-712 authorisation credentials

Authentication

Access to the CLOB API involves a dual-layer verification process:

  1. L1 Authentication (EIP-712): Use your Ethereum private key to sign a structured data object, generating your API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Each request to the API must be signed using your generated 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 the complete set of market information required for your application:

// 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 several order varieties and expiration behaviours:

  • GTC (Good-Till-Cancelled): Remains active in the order book until executed or manually removed
  • GTD (Good-Till-Date): Automatically expires upon reaching a designated moment
  • FOK (Fill-Or-Kill): Either executes in full immediately or is discarded entirely
  • IOC (Immediate-Or-Cancel): Fulfils any available quantity and discards unfilled remainder

WebSocket Streaming

To obtain instantaneous market 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

An elementary reversal-to-mean bot could operate as follows:

  1. Track price movements across chosen markets using WebSocket feeds
  2. Determine an exponential moving average spanning the preceding 24-hour window
  3. Initiate a purchase position when price declines 10%+ relative to that average
  4. Close the position when price recovers toward the average level
  5. Apply Kelly criterion methodology for optimal position sizing

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Incorporate exponential backoff logic when receiving 429 status codes
  • Prioritise WebSocket connections for live data instead of repeated polling cycles
  • Store your private key exclusively in environment configuration, never hardcoded
  • Validate strategies using minimal capital before expanding to larger amounts

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