Skip to content

KM-Osorio/MarketStateEngine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

High-Performance Market State Engine 🚀

C++ Build Status

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).

📖 The Story Behind the Code

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

⚡ Key Technical Features

1. Custom Binary Serialization (Functions.cpp)

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_cast to 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.

2. "Foregone Revenue" Audit System

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.

🛠️ Tech Stack

  • Language: C++17 (STL, Smart Pointers, Stream handling).
  • Build System: CMake.
  • Architecture: Modular design separating Data Access Layer (DAL) from Business Logic.

🚀 How to Build and Run

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 .