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

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
Eurovision 2026 Winner
41%
Fed Rate Cut Q3
47%
ETH > $8k EOY
33%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, monitor live pricing, and oversee your holdings. When paired with the Gamma API for market intelligence, you can develop an end-to-end automated prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional traders. The Polymarket API grants developers unrestricted entry to the globe's premier prediction market platform. Whether your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making bot, this resource equips you with all necessary information to begin.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event information, market listings, outcome conditions, and price history. Open to the public and requires no credentials
  • CLOB API (clob.polymarket.com): Order submission, order withdrawal, position oversight, and live order book snapshots. Demands EIP-712 authorised API keys

Authentication

The CLOB API employs a dual-stage security model:

  1. L1 Authentication (EIP-712): Cryptographically sign a structured-data payload using your Ethereum private key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Cryptographically sign every API call using the generated credentials. The signature encompasses 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 the 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 in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically cancels at a designated timestamp
  • FOK (Fill-Or-Kill): Either executes in full or gets rejected entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity and cancels unfilled portion

WebSocket Streaming

For live market feeds, 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 work as follows:

  1. Track price movements across your target markets through WebSocket feeds
  2. Compute a trailing average price over the preceding 24-hour window
  3. Execute buy orders when price dips 10%+ beneath the average
  4. Execute sell orders once price recovers to the average level
  5. Apply Kelly criterion methodology for position dimensioning

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Implement exponential backoff whenever receiving 429 status codes
  • Favour WebSocket connections for live market data rather than polling intervals
  • Store your private key within environment configuration, never hardcode it
  • Validate strategies with minimal capital before expanding positions

PolyGram members enjoy seamless access to all these markets via an intuitive dashboard — no coding required. 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.