Trading engine for Polymarket's 5 and 15-minute BTC up/down markets, in Rust and Python. Designed, built and ran it in production with my own capital.
- Edge: these markets settle on a Chainlink oracle price, which reached the market ~1.2 s behind Binance (median; 1.8 s p95). Priced every contract off Binance instead, so my fair value moved a second or two before anyone pricing off the oracle feed.
- Pricing: each market is a cash-or-nothing digital option, so P(up) = Φ(d2) under geometric Brownian motion, with volatility from a rolling 10-minute window of 1 s Binance returns and the strike taken from the oracle price at the window open. A nowcast projects the next oracle print from Binance micro-price moves, with the beta fitted online by exponentially weighted least squares.
- Pipeline: Rust (tokio) collectors for Binance L2 depth, the Polymarket order book and the oracle feed drive an L2 book state machine and a streaming feature engine. Output goes to a Python asyncio/uvloop strategy engine over a Unix domain socket as length-prefixed binary frames.
- Execution and risk: fill-and-kill taker orders sized by fractional Kelly on edge after fees, with per-market and global exposure caps and gates for stale books and the last seconds before expiry. An expected-value rule decides whether to hold, sell or buy the other side. Fills arrive over the user WebSocket channel and are reconciled against exchange and on-chain balances. Positions are merged and redeemed on-chain through a Gnosis Safe.
- Research: tick-level backtester with the exchange fee curve, fills against real book depth and capacity limits. Oracle data is indexed by receive time, not the oracle's own timestamp, which keeps a ~1 s lookahead out of the results. Also tested an XGBoost and Bayesian regression ensemble on 193 streaming order-book features, with the Rust feature engine checked against the Python research code by golden-vector tests.
- Production: Docker Compose, a latency benchmark of every exchange endpoint for choosing the server location, Prometheus histograms on the hot path, Grafana dashboards, Loki logs with one run ID shared by the Rust and Python processes, config hot-reload without restarts and real-money integration tests on Polygon mainnet.