A high-performance C++17 Limit Order Book (LOB) engine designed for the Shanghai (SSE) and Shenzhen (SZSE) stock exchanges. This engine implements the Reduction-based Synthesis Logic, processing strictly ordered ApplSeqNum streams to reconstruct the order book state in real-time.
- Performance Oriented:
- Memory Pooling: Custom
ObjectPoolto minimize allocation overhead and fragmentation. - O(1) Lookups: Hash map based order tracking.
- O(1) Removals: Cached iterators allow removing orders from price levels in constant time.
- Memory Pooling: Custom
- Dual Exchange Support:
- SSE (Shanghai): Handles "Balance" based updates. Trades reduce "Maker" volume only (Taker is stateless).
- SZSE (Shenzhen): Standard matching and reduction logic.
- Robust Verification:
- Internal Consistency Checks: Validates map integrity, volume sums, and price ordering.
- Fuzz Testing: Randomized stress tester (
fuzz_test) verified with 10,000+ iterations. - Scenario Regression: Deterministic tests (
test_scenario) for priority, partial fills, and cancellations.
- C++17 compliant compiler (Clang/GCC)
- xmake build system
xmake buildRuns the main simulation demonstrating SSE logic.
xmake run lob_demo1. Deterministic Scenario Tests Validates specific business rules (Time-Priority, Cancellations).
xmake run test_scenario2. Fuzz Testing Runs random stress test with consistency checks.
xmake run fuzz_testinclude/lob/Engine.h: Core OrderBook class definition.Order.h: Order structure and ObjectPool implementation.Level.h: PriceLevel management.Types.h: Common type definitions.
src/Engine.cpp: Implementation of matching and interaction logic.main.cpp: Main entry point for demonstration (Multi-Stock).strategy_demo.cpp: IPC Reader example.fuzz_test.cpp: Generalized fuzz testing suite.test_scenario.cpp: Specific regression scenarios.
- Multi-Stock Support:
MatchingEnginemanages multiple books. - IPC: Shared Memory publishing for low-latency strategy access.
- Run
xmake run strategy_demo <instrument_id>whilelob_demois running.
- Run
MIT