Python signals, C++20 execution
Prediction-market trading system
An automated trading system for prediction markets. Python finds fee-adjusted price gaps between markets, and a separate C++20 engine sizes and places the trades, with messages crossing over shared memory in about 10 microseconds.
- Python
- C++20
- Cap'n Proto
Key numbers
- 10.4µs
median, Python to C++
- 58.8kmsg/s
single-thread peak
- 0
dropped writes at any rate
- 55×
faster than JSON over HTTP
How it works
- Market feedsPolymarket, Kalshi
- Gap scannerPython, fee-adjusted
- Shared-memory ringCap'n Proto, one writer
- C++20 engineKelly sizing
- Circuit breakertrip, then halt
- Exchangeor mock exchange
Decisions that matter
Python decides, C++ executes
Python is good for models and bad at sharing a process: a Python reader on the same ring stalls on the interpreter lock for about 8 ms. Moving execution to its own C++ process brings the median to 10.4 µs.
Benchmarks that cannot flatter
Latency is timed from when each message was scheduled to leave, not when it did. The 55× figure is quoted only at the one rate the JSON baseline could keep up with, and most of the 10.4 µs turns out to be encoding in Python, not the ring.
Bets shrink under stress
Trades start at a quarter of the Kelly bet. One loss over 1% of the bankroll cuts the size for the next ten trades; a 5% drawdown cancels every order and stops the engine until a person resets it.
Results
Limits. Tested against a mock exchange that simulates fills and delays. Several strategies in its plan are not built yet.
