← Back to blog

How to Build a Production-Grade Trading Bot for Polymarket CLOB

Published 2026-07-03 · By Gogoboss

Polymarket uses a hybrid Central Limit Order Book (CLOB): off-chain matching by a centralized operator with on-chain settlement on Polygon via signed EIP-712 orders and the Conditional Tokens Framework (CTF) Exchange contract. This architecture gives sub-second execution but introduces specific challenges for bots.

1. Architecture Overview

  • Hybrid model: Orders are signed client-side (EIP-712), submitted to the CLOB operator, matched off-chain, and settled on-chain only when filled.
  • Unified order book: YES and NO outcomes are linked mathematically (YES_price + NO_price ≈ 1). A buy order on YES appears as a sell on NO.
  • Order types: Primarily limit orders (GTC by default). Supports FOK and FAK.
  • Authentication: EIP-712 signatures + HMAC for API keys. Different signature_type depending on wallet (EOA=0, Proxy=2, etc.).

2. Infrastructure Requirements

  • Low latency: Aim for <100ms median RTT to clob.polymarket.com. Use VPS in Europe (Dublin/Frankfurt) or US-East.
  • Reliable RPC: Private Polygon RPC (not public nodes) to avoid rate limits and delays during settlement.
  • Language choice: Rust or Go for best performance. TypeScript/Python acceptable for prototyping.

3. Core Components You Must Implement

A. Real-time Order Book Management

// Use official @polymarket/clob-client or py-clob-client
const book = await client.getOrderBook(tokenId);

// Maintain local L2 book
interface OrderBook {
  bids: Array<{price: string, size: string}>;
  asks: Array<{price: string, size: string}>;
  hash: string;           // for change detection
  timestamp: string;
}
  • Subscribe to WebSocket: wss://ws-subscriptions-clob.polymarket.com/ws/market
  • Handle events: book (full snapshot), price_change, best_bid_ask, last_trade_price
  • Always validate against book.hash to detect inconsistencies.

B. Order Creation & Submission Orders must be signed with correct parameters:

  • token_id
  • price (respect tick_size: usually 0.01 or 0.001)
  • size (in shares, respect min_order_size)
  • side (BUY/SELL)
  • neg_risk flag for negative-risk markets

Use createOrder() from the SDK, then postOrder() with appropriate OrderType (GTC, FOK, FAK).

C. Slippage & Impact Calculation Implement a function that walks the book:

def calculate_vwap(book, side: str, size: float) -> float:
    levels = book.bids if side == "BUY" else book.asks  # reverse logic
    remaining = size
    total_cost = 0.0
    for level in levels:
        level_size = float(level['size'])
        take = min(remaining, level_size)
        total_cost += take * float(level['price'])
        remaining -= take
        if remaining <= 0:
            break
    return total_cost / size if size > 0 else 0

Add safety buffers (2–8 cents depending on market liquidity and time to expiration).

D. Latency & Rate Limit Handling

  • Order placement limit: ~60/min per key (bursts higher)
  • Use exponential backoff + jitter
  • Batch orders when possible (up to 15 in one call)
  • Monitor best_bid_ask events for top-of-book changes

4. Critical Edge Cases & Gotchas

  • Final minutes: Volatility and slippage explode in last 60–120 seconds.
  • Tick size changes: Markets near 0 or 1 can change tick_size. Monitor tick_size_change events.
  • Neg-risk markets: Special handling required for capital efficiency.
  • Partial fills: Expect them. Track leavesQuantity.
  • Order book hash: Use it to verify your local state.
  • Fees: Maker rebates vs taker fees — prefer maker orders when possible.

5. Recommended Backtesting Approach

Standard OHLC backtests are useless. You need:

  • Reconstructed historical order books (tick-level)
  • Realistic simulation of spread, slippage, and latency
  • Modeling of partial fills and queue position

This is where most home-built bots fail.

Ready-Made Solution

Building and maintaining all of the above (order book reconciliation, WebSocket resilience, fee/slippage modeling, risk engine, etc.) takes significant engineering effort.

GoGoBots provides a production-ready environment with:

  • Accurate CLOB simulation using real historical tick data
  • Built-in spread, slippage, and latency modeling
  • Order book impact calculation
  • Strategy optimization under realistic conditions

You can focus on alpha generation instead of infrastructure.

Start Building & Testing CLOB Strategies Free