A high-frequency trading simulation engine focused on low-latency state persistence and audit-grade inventory management.
This project demonstrates the optimization of I/O operations using custom binary serialization instead of standard text parsing, and implements complex business logic to prevent "Inventory Black Holes" (untracked lost revenue).
I wrote an article detailing the engineering challenges and optimizations in this project:
👉 Read on Medium: 4 Ways I Sabotaged My High-Performance C++ Engine
Standard text I/O (JSON/CSV) is too slow for high-frequency contexts. I implemented a raw memory dump strategy:
- Zero-Copy Logic: Uses
reinterpret_castto write integer memory layouts directly to disk. - Reduced Footprint: Stores string lengths as 4-byte integers rather than delimiters, reducing file size and parsing overhead.
- Direct Memory Access: Bypasses standard stream formatting for maximum throughput.
The engine doesn't just reject orders when stock is low; it quantifies the loss.
- Partial Fills: Algorithms automatically split orders based on available inventory.
- Missed Opportunity Logging: Calculates and records the exact revenue lost due to stockouts (
registerMissLog), essential for post-trade analysis.
- Language: C++17 (STL, Smart Pointers, Stream handling).
- Build System: CMake.
- Architecture: Modular design separating Data Access Layer (DAL) from Business Logic.
This project uses CMake. Ensure you have a C++ compiler (GCC/Clang/MSVC) installed.
# 1. Clone the repository
git clone [https://github.com/KM-Osorio/cpp-market-state-engine.git](https://github.com/KM-Osorio/cpp-market-state-engine.git)
cd cpp-market-state-engine
# 2. Create build directory
mkdir build
cd build
# 3. Configure and Build
cmake ..
cmake --build .