Polymarket Engine
A production algorithmic-trading engine for Polymarket's order book — five alpha strategies, unified behind a fifteen-gate risk architecture.
Polybot
Every trade has to pass fifteen gates in order — liquidity, toxicity, volatility, evidence, nonce, latency, inventory — before a single order leaves the machine.
What it does
The engine detects and exploits statistical mispricing in prediction markets, then routes any candidate trade through a sequential all-or-nothing validation pipeline that enforces risk limits and sizes positions before submission. The organising idea is a single decision inequality: map the market state to a go / no-go, where every term is a named risk constraint.
Five alpha strategies
- Bayesian cross-market arbitrage — detecting violations of the law of total probability across dependent markets.
- Intra-market rebalancing — exploiting sum-to-one deviations between YES/NO within a market.
- Volatility-adjusted market making — Avellaneda–Stoikov in logit space, spreads tuned to order-flow toxicity (VPIN).
- Ensemble forecasting — a twelve-model LLM ensemble aggregated in log-odds, weighted by Brier score and Platt-calibrated.
- Whale copy-trading — tracking historically profitable wallets on-chain and mirroring, with counter-position size reduction.
How it's built
A Python/Rust hybrid: Python carries strategy logic, ML and backtesting; execution and order-book management run through NautilusTrader's Rust core, signing on Polygon with EIP-712. An eleven-feature state vector feeds the fifteen gates — liquidity depth, VPIN toxicity, volatility guardrail, contrarian-evidence search, nonce and RPC sync, latency-adaptive order type, inventory limits, a TimesFM price guard, fractional-Kelly sizing, and a global kill switch. Sizing uses Kelly with explicit ambiguity aversion for model disagreement; validation is walk-forward across 34+ out-of-sample windows with Monte-Carlo slippage and fee modelling. Every gate decision is logged to JSONL for exact backtest replay.
Signals of rigour
Log-odds (not arithmetic) ensemble aggregation, so the maths stays Bayesian-coherent. VPIN as a toxicity gate on entry. A combinatorial check that a new position doesn't violate the Bayesian consistency of the whole portfolio. Kill switches on daily, monthly and drawdown loss. It reads like a quant desk's process, encoded.
Core feature
The engine's core: gates.py — the fifteen-gate pre-trade pipeline (G1 liquidity depth through G15 kill switch). Every candidate trade must pass all fifteen gates in order; a single failure halts it before an order is ever signed.