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

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.

Sarah Whitfield
Markets Editor — Political Forecasting · · 3 min read
✓ Fact-checked · 📅 Updated 28 April 2026 · 3 min read
PolyGram
Trending · Politics · Sports · Crypto
FIFA World Cup 2026
64%
2028 Dem Nominee
52%
Eurovision 2026 Winner
41%
Trade →

Key takeaway: Polymarket's CLOB (Central Limit Order Book) API enables you to submit orders programmatically, consume live price feeds, and handle your account positions. When paired with the Gamma API for market intelligence, you can construct a completely autonomous prediction market trading bot.

Algorithmic trading belongs to everyone, not just institutional finance. The Polymarket API opens the world's largest prediction market to developer automation. Whether your goal is to streamline a straightforward rebalancing approach or construct an advanced market-making engine, this resource walks you through the essentials.

API Architecture Overview

Polymarket makes available two principal APIs:

  • Gamma API (gamma-api.polymarket.com): Event catalogues, market listings, condition identifiers, and time-series pricing. Openly accessible without credentials
  • CLOB API (clob.polymarket.com): Order submission, removal, account holdings, and live order book snapshots. Demands EIP-712 signed API credentials

Authentication

CLOB API security operates across two tiers:

  1. L1 Authentication (EIP-712): Sign a structured message using your Ethereum key to generate API credentials (apiKey, secret, passphrase)
  2. L2 Authentication (HMAC-SHA256): Sign every request with your generated credentials. The signature incorporates the timestamp, HTTP verb, endpoint path, and payload

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 market intelligence required for your bots:

// 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 instructions:

  • GTC (Good-Till-Cancelled): Remains in the order book until executed or withdrawn
  • GTD (Good-Till-Date): Automatically expires at a designated moment
  • FOK (Fill-Or-Kill): Executes fully or rejects entirely
  • IOC (Immediate-Or-Cancel): Executes available quantity, discards remainder

WebSocket Streaming

To obtain live market feeds, 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 mean-reversion approach would:

  1. Track pricing movements across your target markets through WebSocket feeds
  2. Determine a moving average across the preceding 24-hour window
  3. Initiate purchases when quotes sink 10%+ beneath the moving average
  4. Exit positions when valuations recover to the moving average level
  5. Apply Kelly criterion methodology for stake determination

Rate Limits and Best Practices

  • CLOB API: 100 requests per 10 seconds per API key
  • Implement exponential backoff when receiving 429 rate-limit responses
  • Favour WebSocket subscriptions for live market data rather than repeated polling
  • Store your private key in environment configuration, never hardcode it
  • Validate your approach using minimal capital before expanding position sizes

PolyGram members gain entry to these markets via a streamlined dashboard — no coding necessary. Start trading on PolyGram →

Sarah Whitfield
Markets Editor — Political Forecasting

Sarah has tracked political prediction markets and election forecasting since the 2020 US cycle. Focus: US presidential, congressional, and UK parliamentary contracts.