Market Microstructure Model - Central Limit Order Book Simulation

GitHub
Overview
C++ limit order book simulation modeling execution, queue priority, and liquidity dynamics in a price-time priority exchange environment.
Built to study how order flow and queue position determine execution outcomes in fast-moving markets.
Trading Problem
Execution in order-driven markets is determined by microstructure, not price alone.
Queue position, order flow, and liquidity dynamics determine realized PnL.
Core Idea
A price-time priority limit order book is simulated to study:
- Execution probability
- Liquidity formation
- Order flow impact on short-term price behavior
Trading Mapping
This models:
- Passive execution risk
- Market making queue dynamics
- Short-term liquidity shifts
- Adverse selection from order flow imbalance
Key Mechanisms
- Price-time priority (FIFO matching)
- Market / limit / cancel order flow
- Liquidity evolution under stochastic arrival processes
Key Insights
- Queue position is a primary driver of fill probability
- Displayed liquidity ≠ executable liquidity
- Order flow imbalance creates short-term directional pressure
- Execution is inherently path-dependent
Core Takeaway
Execution quality emerges from microstructure, not price levels.
Market Microstructure & Execution Visualizations
Benchmarks comparing execution throughput, matching latency, and order book query performance across C++ vs Python implementations.
C++ Query
High-Throughput Price-Time Priority Matching Engine (C++ Implementation)
C++ limit order book processing 99,999 order events in ~0.67s, demonstrating low-latency execution, queue-based matching, and high-frequency order flow processing.
Python Query Speed
Reference Order Book Engine for Logic Validation (Python Baseline)
Python implementation processing identical order flow (~6s), used as correctness benchmark for execution logic, matching consistency, and state parity validation.
C++ Query Snapshot
Low-Latency Order Book State Query for Liquidity and Depth Inspection
Efficient retrieval of live and historical order book states enabling real-time liquidity inference and execution timing analysis.
Trading Ladder View 2
Reconstructed Order Book Depth Snapshot for Liquidity Structure Analysis
Full market depth reconstruction illustrating resting liquidity distribution and executable order book structure at a given timestamp.
Trading Ladder View (Add and Cancel)
Order Book Snapshot (Add + Cancel functionality)
Order addition / cancellation behavior demonstrating liquidity removal, depth reshaping, and microstructure-driven book evolution.