Real-time trading simulation stack to study market microstructure. It ingests live L2 order book data, runs pluggable matching algorithms in a C++ engine, and streams results to a React dashboard — all in real time.
- Engine: C++ matching engine + WebSocket API (real-time in/out)
- Data: Live L2 depth (snapshot + incremental) from Binance
- UI: React dashboard for live depth, trade entry, and executions
- Market microstructure: PTM and Pro Rata matching, TIF (GTC/IOC/FOK), L2→synthetic L3 modeling
- Real-time systems: low-latency path from data -> engine -> UI via WebSockets
- Systems design: shared per-ticker order books, event dispatcher, observable patterns
- Measured performance: millisecond latency and high orders/sec throughput
- Real-time order book ingestion
- Startup snapshot + incremental updates
- Validation and syncing to maintain a consistent L2 book
- Matching algorithms (pluggable)
- Price-Time Matching (PTM)
- Pro Rata
- Order types and TIF
- Market and Limit
- GTC, IOC, FOK
- Real-time UI
- Live L2 depth, recent trades, and trade entry
- Multi-user scalability
- Shared per-ticker order book instance: all connected users share the same live book and receive updates simultaneously (memory-efficient and performant)
- Extensible connectivity
- Endpoint Providers abstraction to support multiple market data sources (Binance today; other exchanges/providers can be added)
- Engine (C++)
- MatchingEngine interface with swappable strategies (PTM, Pro Rata)
- OrderBook maintains live L2 state (bids/asks), snapshot apply + incremental sync
- Event Dispatcher: isolates domain events (book updates, executions) from transport (WS)
- Observable/Observer: multiple components publish/subscribe without tight coupling
- Shared per-ticker order book instances for multi-user efficiency
- Data Connectivity
- Endpoint Provider wraps REST snapshot + WS streams (Binance)
- Interface allows plugging other exchanges or historical replays
- Dashboard (React)
- WebSocket client for live depth and trade events
- Trade ticket: side, type, TIF, strategy selection
- Live visualizations and execution results
- Average latency (order received → completion)
- PTM: 7.728 ms
- Pro Rata: 8.0022 ms
- Average throughput
- PTM: 120 orders/sec
- Pro Rata: 86 orders/sec
Why Pro Rata is slower: Binance exposes L2 (aggregated) depth only. To emulate queue dynamics, the engine generates realistic synthetic L3 “sub-orders” within each price level. PTM treats each price level as a single order and requires no L3 simulation.
- Real-time market data sourcing
- Finding suitable free real-time data was challenging. The initial plan targeted equities, but free, reliable real-time equity feeds are limited, so the project uses crypto (Binance) instead.
- Reproducible simulation against a live book
- Since trades cannot be placed directly against the exchange’s live order book, the engine snapshots the book at the instant an order is received and then runs the simulation against that frozen state for determinism and replayability.
- L2-only depth and synthetic L3
- Binance depth is limited to L2 (aggregated quantities per price). To bridge the gap for algorithms that depend on queue position (e.g., Pro Rata), the engine generates plausible sub-orders inside each level using real-world-like distributions.
- Scalable design with OOP patterns
- Implemented Observable/Observer to decouple the engine from transport and UI. Multiple classes can publish/subscribe to WebSocket-bound events cleanly.
- Endpoint Providers abstract data sources so the same engine can plug into other exchanges or historical replays with minimal changes.
- Event isolation via Dispatcher
- Introduced an Event Dispatcher to isolate engine and order book events from WebSocket concerns. This was a significant challenge that paid off in modularity and testability.
- Shared order book per ticker
- For multiple concurrent users, the application maintains one shared order book instance per ticker (see engine controller). All users receive synchronized updates from the same book, reducing memory footprint and improving performance.
- Financial microstructure literacy
- Deepened understanding of trades, quotes, orders, bids, asks, time-in-force, and matching policies.
- Historical replay/backtesting mode
- Benchmark harness with p50/p95/p99 latency per symbol; profiling
- Unit/integration tests across order book sync and strategies
- Docker Compose for one-command setup
- Additional data providers and true L3 mode if available
- Market data: Binance (public endpoints)
- Educational project; not for production trading