Play
low-latency-trading-ecosystem
2023 · C++ / Qt · A full exchange plus market-participant ecosystem
A multithreaded trading ecosystem that hosts an exchange supporting multiple clients. The system ensures orders are fairly executed on a first-come-first-serve basis, sequenced by software receive time before the matching engine ever sees them. The exchange also runs basic market maker and liquidity taker algorithms trading different strategies against it.
Market data is distributed over UDP multicast, so the system also solves what happens when a packet doesn’t arrive: any client that misses an update can rebuild its order book from a periodic snapshot plus the incremental updates that followed it, resyncing without stalling the feed for everyone else.
Components
- Matching engine — builds and maintains the limit order book, matches crossing orders, and publishes responses and market-data updates.
- Order gateway server and client — TCP connection management with a
FIFOSequencerordering requests by arrival time to enforce first-come-first-serve. - Market data publisher and consumer — incremental multicast stream plus periodic full snapshots, with gap detection and resync on the consumer side.
- Feature engine, position keeper, order manager, risk manager — the client-side trading stack: fair-price and aggressive-trade-ratio signals, PnL and position tracking, order lifecycle, and pre-trade risk limits.
- Market making and liquidity taking algorithms — capturing spreads with passive quotes, and crossing them with aggressive orders.
Learning outcomes
- Minimizing latency using templated lock-free FIFO queues to move data between threads, with critical components pinned to isolated CPU cores.
- Profiling latencies and execution times with RDTSC across ~20 hop points, focusing on mean, range and spikes rather than averages alone.
- Handling UDP loss recovery via paired incremental and snapshot data streams.
- Compiler hinting and attributes to maximize performance —
const,constexpr,noexcept,inline,__builtin_expect. - Packing data structures, and good design and optimization technique generally.
- Qt usage for the user interface, with Valgrind for memory debugging.