🎁 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, consume live price streams, and handle your portfolio. Paired with the Gamma API for market information, you can construct a completely self-executing prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional investors. The Polymarket API provides developers with unrestricted access to the globe's foremost prediction market platform. Whether you're looking to streamline a straightforward rebalancing approach or develop an advanced market-making bot, this resource walks you through all the essentials.

API Architecture Overview

Polymarket makes available two primary APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and past performance records. Freely accessible without login credentials
  • CLOB API (clob.polymarket.com): Submitting trades, removing orders, controlling holdings, and accessing live order book snapshots. Demands EIP-712 derived API credentials

Authentication

CLOB API security operates across two distinct stages:

  1. L1 Authentication (EIP-712): Create a signed typed-data payload using your Ethereum wallet's private key to obtain API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every call to the API using the obtained credentials. The signature incorporates the request time, HTTP verb, resource 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 essential market information required for your bot:

// 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): Remains active in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a predetermined moment
  • FOK (Fill-Or-Kill): Either executes fully or gets rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity and discards unfilled remainder

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 mean-reversion approach could operate as follows:

  1. Track price movements across selected markets using WebSocket feeds
  2. Compute an exponential moving average spanning the preceding day
  3. Purchase when the price declines 10%+ relative to the computed average
  4. Liquidate holdings once the price recovers to 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
  • Consistently apply exponential backoff when encountering 429 status codes
  • Favour WebSocket connections for live information rather than repeated polling
  • Store your wallet's private key within environment settings, never hardcoded
  • Validate strategies with minimal capital before expanding positions

PolyGram members gain entry to all these markets via an intuitive dashboard — coding expertise is 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.