Skip to content
Khaled.dev
← Back to work

Solo engineer — design, on-chain integration, execution engine · 2025

Polymarket Copy-Trading Bot

Mirrors top prediction-market traders on Polymarket with risk-scaled position sizing and sub-second order placement.

Polymarket Copy-Trading Bot

Stack

  • TypeScript
  • Node.js
  • viem
  • Polygon
  • WebSockets
  • Redis
  • Docker

Links

Overview

What it is

A self-hosted bot that watches a curated set of profitable Polymarket wallets on-chain and replicates their positions in real time. It listens to the Polygon mempool and Polymarket's CLOB websocket, decodes order events, and re-sizes them against the operator's own bankroll and risk limits.

The hard part was not the copying — it was avoiding adverse selection. The bot models each followed trader's historical edge, decays stale signals, and refuses to chase fills that have already moved past a configurable slippage band. A circuit breaker halts trading on anomalous spread widening.

The problem

What needed solving

Profitable Polymarket traders move fast, and by the time a human notices a winning position the edge has usually evaporated. Naïvely copying them is worse than not trading at all: you inherit their adverse selection and pay the spread they already crossed.

I wanted to mirror a curated set of wallets automatically, but only when the trade still had positive expected value after slippage — and never in a way that could blow up the bankroll on a single anomalous fill.

The approach

How I built it

I ingested signals from two sources for redundancy: the Polygon mempool for pending transactions and Polymarket's CLOB websocket for confirmed order events, deduplicating by order hash so a trade is never mirrored twice.

Each followed wallet carries a rolling model of its historical edge. Signals decay over time, and the execution engine refuses any fill that has already moved past a configurable slippage band. A circuit breaker halts all trading when spreads widen anomalously.

Position sizing is risk-scaled against the operator's own bankroll rather than copied 1:1, so a whale's $50k bet becomes a proportional fraction of available capital.

The outcome

Results

<1s
Median signal-to-order latency
0
Followed wallets tracked
0.0%
Uptime over live run
  • Ran live for months against a curated set of wallets with sub-second median latency from signal to placed order.
  • The slippage guard and circuit breaker eliminated the tail losses that killed an earlier naïve copy approach.

Highlights

4 things worth calling out

Sub-second mirror latency from signal to placed order

Risk-scaled sizing keyed to each followed trader's measured edge

Mempool + CLOB websocket ingestion with idempotent order dedup

Circuit breaker on anomalous spread widening

Gallery

A closer look

Polymarket Copy-Trading Bot screenshot
Polymarket Copy-Trading Bot screenshot