Stock Trading Simulator (C++)

Low-latency matching engine with a price/time-priority order book, trades, and P/L tracking — built in modern C++.

C++17STLMultithreadingFile I/OUnit TestsSockets (optional)
C++ trading simulator order book and trade log preview

Flow: incoming orders → price/time-priority book → match → trade events → portfolio & P/L update → persisted to disk.

Overview

I built a C++ trading simulator that focuses on **systems fundamentals**: an in-memory order book, a deterministic matching engine, and fast data structures for price levels and orders. The simulator matches limit/market orders using price/time priority, emits trade events, updates positions and realized/unrealized P/L, and persists sessions to disk for replay and analysis.

Goals

  • Implement a correct, deterministic **matching engine** with price/time priority.
  • Maintain **portfolio & P/L** with fills, partial fills, and cancels.
  • Provide repeatable runs via **session persistence** and replay.

My Role

  • Core engine design (order book, matcher, events, risk checks).
  • Performance profiling & concurrency experiments (read/write separation).
  • CLI tools, file formats, and unit/integration tests.

Architecture

Highlights

Deterministic Matching

Strict price/time priority with FIFO queues per price level — predictable and testable outcomes.

Fast Data Structures

Ordered maps for price levels + intrusive IDs for O(1) cancel/replace within a level.

Replayable Sessions

Append-only logs and snapshots enable run replay, debugging, and profiling on real market-style feeds.

What I Learned

Next Steps