Extension 4. `engineering-challenge latency EXCHANGE OUT.csv` opens 16 connections to the same busy markets and writes every copy of every change; `scripts/latency/analyse.py` gives each connection's speed, whether it persists, what keeping the fastest would gain, lateness by address, and lag with the clock's offset. LATENCY.md writes up four runs: on Polymarket speed persists but is worth under a millisecond, at the median only; on Kalshi's demo keeping the fastest pair lowers p99 by 28% and 42%, the threshold agreed before the runs. So the collector now recycles a Kalshi connection whose mean lateness stays, 3 minutes running, in the slowest quarter and above twice everyone's, ahead of its hourly turn. Kalshi's rule measures each duplicate's lateness; the orchestrator judges once a minute. A duplicate's lag in Polymarket's minute line is now its "lateness". Roadmap milestone 7, roadmap/07.
Read before getting started!!
First, read src/main.rs. Then, some background on this repo:
This repo uses the FIX SBE standard
for writing binary messages. The rust code abstracts this away for you, and you can simply use the helpers, as demonstrated in main.rs.
More background, in case you are curious!
FIX SBE is defined in XML, which I find extremely cumbersome to edit, especially when updating schemas frequently. To solve this, I have also introduced some helper code that takes our own custom YAML format, and turns it into FIX SBE XML, which in turn is used to generate rust code to encode and decode the messages. You don't need to edit any of these files. This explanation is simply to help you understand the origins of the various files in this repo.
If you're curious to see the YAML schema, take a look at challenge_orderbook.yaml.
We also use a custom timestamp field, so that the Rust struct can use
chrono::DateTime in the generated struct, and in SBE schema, it is a uint64
representing the timestamp as the number of microseconds since unix epoch.