How we built it
- Python first: we started with a Python bot on Optiver's client library, with a scorecard, a config per experiment, and a log of every experiment we ran (26 in total, E1 to E26).
- Measuring before optimizing: we recorded the public market feed and wrote analysis scripts that rebuild every "snipe race": who traded first, how many ticks the leader moved, and which place in the queue we got.
- A local race benchmark: a stand-in exchange on our own machine (the same wire protocol, a fake login) replays price jumps with hundreds of messages behind them. It measures how fast the bot reacts without ever touching the live exchange.
- Fixing Python's hidden delay: Optiver's client decodes a whole burst of messages before an order sent from a handler can leave. Three small event-loop yields after each order cut our benchmark reaction from 11 ms to 2.4 ms (with 300 messages behind the jump).
- A lean C++ sniper: we rewrote the hot path in C++ with Cap'n Proto and KJ coroutines. It reads messages in place and decides in about 0.03 ms. It ships as a static binary built in Docker.
- The network path: the exchange's private address inside the cloud network saved about 0.5 ms each way compared with the public one.
- Home reversion in C++: we moved it into the same binary, then extended it to all 8 stocks with higher caps.
Challenges we ran into
- The fastest language did not help at first. Our C++ bot made its decision in 0.03 ms, yet it still finished behind other teams. The delay was in the exchange: it processes the order flow after a jump one order at a time, about 0.5 ms per place in the queue, and its trade data reaches us about 2.5 ms after the trade itself.
- Testing without breaking the live bot. Connecting with the team login kicks the running bot, so every test had to run against our own stand-in exchange.
- Exchange resets in the middle of a run. PnL and positions dropped to zero, trade IDs restarted, and connections were refused. The bot had to recover by itself.
- Bugs that only showed up live: a scorecard that ignored the positions a run started with, a reconnect that reused a dead connection, and a benchmark that deadlocked on shutdown.
- Stop-losses looked like a good idea. We tested per-stock stops, deviation stops and a portfolio breaker on recorded data. Every one of them lowered PnL and none of them made the worst drop smaller, so we left them out.
Accomplishments that we're proud of
- Snipe queue: our median place improved from 24th to 14th.
- PnL rate: from about +1,470 per hour with our first setup to about +2,900 per hour with the final C++ bot (E26), with a largest drop of 171 before the reset. These runs come from different market windows, so part of the gap is the market and not only us.
- Every change was measured: each change got an experiment number, a benchmark and a live comparison, with tests, lint and type checks on every PR.
- It survived a live exchange reset: the bot reconnected and rebuilt its positions with no one touching it.
What we learned
- Measure first. Our guesses about why we were slow were mostly wrong. The bottleneck kept moving: Python's event loop, then the network path, then the exchange's own queue.
- A faster language only helps once it's your bottleneck. After our code took 0.03 ms, the remaining gap was the network and the queue.
- Simple strategies win. Optiver hinted that the best solution is about 310 lines long. Our best results came from deleting complexity, not adding it.
- Backtest your intuitions: a "safe" stop-loss can quietly cost you money.
What's next for dilem-optiver
- Explain the queue: study exactly how the exchange orders simultaneous requests, to learn what still decides the snipe race.
- Adaptive home prices: let the home values adjust while the bot runs, instead of setting them by hand.
- Smarter sizing: size snipes by the stale volume and our current position, not one fixed size.
- More replays: run recorded market days through the stand-in exchange, so we can test whole strategies offline and not only reaction speed.