QD / MADE BY AI
I built a Python cryptocurrency arbitrage proof of concept to verify that the opportunity was real and could be profitable, then migrated the engine to Rust and optimized latency.
I also built a real-time market data service in Rust. It ingests the top 20 L2 order-book levels (the API limit) from two exchanges across 11 pairs, publishes to ZeroMQ, and persists data in TimescaleDB.
- 2 exchanges11 pairs · L2 top 20
- Rust market dataDecode · normalize · publish
- ZeroMQ Pub/SubArbitrage engine
Rust market data → TimescaleDB persistence
Market data / tick-to-publish
Frame bytes to subscriber receipt. Excludes WebSocket read and TLS decryption.
End-to-end latency · µs
| Stage · µs | p50 | p99 | p99.9 |
|---|---|---|---|
| JSON decode | 4.88 | 6.71 | 7.21 |
| Parse to OrderBookData | 9.96 | 13.54 | 17.76 |
| Build payload | 14.13 | 18.72 | 25.30 |
| Serialise payload | 2.83 | 3.83 | 4.17 |
| ZMQ socket.send | 0.17 | 0.46 | 0.96 |
| CPU subtotal | 31.97 | 43.26 | 55.40 |
| Handoff | 34.39 | 54.61 | 88.77 |
| Tick-to-publish | 74.43 | 99.33 | 119.94 |
Arbitrage engine / tick-to-decision
Depth 5 optimization: p99.9 fell from 3,000 ns to 792 ns (-74%); allocations fell from 36 to 0.
Python and Rust comparison
ZeroMQ message bytes in, arbitrage verdict out. Pre-socket only; excludes network and exchange time. Depth 5; 500,000 iterations after 50,000 warmup.
| Implementation · ns | p50 | p99 | p99.9 |
|---|---|---|---|
| Python, JSON | 2,667 | 3,750 | 9,666 |
| Naive Rust, JSON | 1,250 | 1,750 | 1,958 |
| Optimized Rust, JSON | 458 | 625 | 709 |
After the internship / binary wire experiment
JSON deserialization is 99.6% of the decision path; arithmetic takes 7 ns. I own the ZeroMQ publisher, so I replaced JSON with a 48-byte fixed frame.
- p50
- 2 ns
- p99
- 3 ns
- p99.9
- 5 ns
Measured after the internship. Excluded from the internship benchmark results above.