Four self-balancing AVL trees organize all active orders: buyTree, sellTree, stopBuyTree, stopSellTree. Each node is a price level (a Limit) containing a doubly-linked list of orders in FIFO order. Edge pointers give O(1) access to the best bid and best ask at all times. AVL rotations keep tree height at O(log M) where M = distinct price levels.
AVL TREEO(1) BEST BID/ASKFIFO DLL
⇄
Matching Algorithm
Price-time priority matching: incoming orders match against the best opposite price level. The engine uses O(1) hash-map lookups (unordered_map<OrderId, Order*>) for cancel and modify — no tree traversal. Each execution generates FIX-style ExecutionReport messages.
PRICE-TIME PRIORITYO(1) CANCELHASH MAP
⚅
Market Simulation
Orders generated using N(μ=mid, σ=0.50) around the mid price. A weighted-probability selector picks order types: ~20% limits, ~10% markets, ~35% cancels, ~15% modifications, ~10% stop orders, ~10% stop-limits — mimicking real microstructure.
NORMAL DISTWEIGHTED PROBMICROSTRUCTURE
★
Scenarios
Mixed: All order types balanced. Basic: Limit & market only. HFT: High-frequency bursts with aggressive cancels. Stress: Maximum throughput with large sizes and concentrated levels.
4 SCENARIOSCONFIGURABLE
⚙
C++ Architecture
C++20 with raw-pointer AVL trees for maximum hot-path performance. Hash maps (unordered_map) provide O(1) lookups. Atomic JSON snapshots every 100ms. Single function-call pipeline for submission, validation, matching, and reporting.
C++20RAW POINTERSATOMIC I/O
⏲
Latency Tracking
Every op instrumented with chrono::steady_clock at nanosecond resolution. Rolling 1,000-sample window computes P50, P95, P99, min/max, mean. AVL rotation counting tracks tree health under load.