When I came to America from Dubai with nothing but a suitcase and a plan, I didn't know those plans would lead through MIT, Jump Trading, and Alameda Research. But the engineering patterns I learned along the way are exactly what you need to build a production-grade trading bot for Polymarket Perps. This guide is the architecture I wish someone had written down in October 2026.
The big picture
A perps trading bot has four layers, and every layer deserves its own process:
- Data ingestion — subscribe to websocket feeds for orderbook, trades, and index prices. Never poll REST in a loop for data you can stream.
- Strategy engine — takes normalized market state, decides actions. Pure function in, orders out. No hidden state.
- Execution — signs and submits orders, handles partial fills and retries with idempotency keys.
- Risk management — position limits, drawdown limits, kill switch. This layer overrides everything else, always.
When I was at Jump, the desk principle was simple: the risk layer must be able to cancel every order in one operation, without asking the strategy engine for permission. Build that first.
Data ingestion details
For Polymarket Perps you want:
- a persistent websocket connection per market group, with sequence numbers checked on every message
- a REST fallback for snapshots on reconnect
- a clock-sync routine so you can reason about latency honestly
Reconnect logic is where hobby bots die. Exponential backoff, snapshot-then-delta recovery, and a watchdog that restarts the whole ingestion layer if staleness exceeds your threshold.
Strategy engine: keep it boring
Market making on perps is quoting two-sided prices around a fair value you compute from the underlying prediction market. Your fair value model can start simple: index price plus a skew adjustment from orderbook imbalance.
The complexity belongs in inventory management, not in signals. Track net position, skew quotes away from inventory extremes, and cap notional per market. A boring strategy with good inventory control beats a clever strategy with none.
Execution: idempotency or bust
Every order submission carries a client-generated idempotency key. On timeout, query order state before retrying — never blind-retry submissions. Partial fills reduce remaining size atomically.
Rate limits are part of the API surface. Budget your calls like memory in embedded systems: fixed allocation, no leaks.
Risk management is the product
- Max position per market — absolute notional cap.
- Max drawdown per day — when hit, flatten and stop until next session, automatically.
- Kill switch — one operation cancels all quotes and orders. Test it weekly.
- Sanity checks — reject any order that moves your position beyond limits, no matter what the strategy says.
At Alameda I watched risk discipline decay gradually and then suddenly. The lesson: automation of limits is not optional; humans are terrible at cutting their own losses in the moment.
What's next
In the next posts I'll walk through the funding-rate mechanics of Polymarket Perps (what the docs say, term by term), then margin modes and the liquidation waterfall with real numbers.
The full architecture with code lives in my GitHub repo: polymarket-mm-bot. It's MIT licensed — take it, fork it, build on it.
In America, if you work hard and smart, you win. Not financial advice — trading involves substantial risk of loss.
Top comments (0)