A high-performance, low-latency Order Management System (OMS) built from scratch in modern C++20. Designed for high-frequency trading (HFT) and multi-exchange order routing with deterministic state transitions, idempotency, and strict concurrency semantics.
-
Strict Order State Machine: Immutable state transitions governed by an
OrderStateMachinegatekeeper. Prevents invalid state shifts (e.g.FILLED->LIVEor direct skips). -
Invariant Guarantees: Enforces
$\text{filledQuantity} + \text{remainingQuantity} = \text{quantity}$ and zero overfills at runtime. - Volume-Weighted Average Price (VWAP): Precise fill price tracking across multiple partial execution reports.
-
Modern C++20: Strongly-typed
enum class,constexpr std::string_view,std::chrono::steady_clocknanosecond timing,[[nodiscard]], andnoexcept. - Zero Allocation Hot Paths: Pass-by-reference design to eliminate heap allocation overhead during order transitions.
src/
core/
Types.h # Strongly-typed enums (Side, OrderType, OrderStatus, etc.)
Order.h # Pure data model for an Order
Order.cpp # Implementation helpers
OrderStateMachine.h # State machine transition rules & fill/cancel/replace logic
OrderStateMachine.cpp
tests/
test_state_machine.cpp # Comprehensive C++20 unit test suite
CMakeLists.txt
- C++20 compatible compiler (
clang++$\ge 12$ org++$\ge 10$ ) -
CMake$\ge 3.20$ (optional, direct build supported)
mkdir -p build
clang++ -std=c++20 -Wall -Wextra -Wpedantic src/core/OrderStateMachine.cpp tests/test_state_machine.cpp -o build/test_state_machine
./build/test_state_machinemkdir -p build
cd build
cmake ..
make
./test_state_machine- ✅ Legal order lifecycles (
NEW→PENDING_NEW→LIVE→PARTIALLY_FILLED→FILLED) - ✅ Volume-Weighted Average Price (VWAP) precision math
- ✅ Illegal state transition rejections (
FILLED→LIVE,NEW→FILLED) - ✅ Overfill prevention bounds check
- ✅ Cancel request and state rollbacks (handling 0 fills vs partial fills)
- ✅ Replace/amend price and quantity acknowledgement flows
- Step 1-4: Core Architecture, Entities, Invariants & State Machine
- Step 5: ExecutionReport Processor & Idempotency Manager
- Step 6: OrderManager & Thread-Safe Sharding
- Step 7: Exchange Adapter Interface & Exchange Simulator
- Step 8: Cancel & Replace Engine under Network Race Conditions
- Step 9: Multi-Threaded Concurrency Engine & Event Bus
- Step 10: Recovery & State Reconciliation Manager
- Step 11: Risk & Position Manager
- Step 12-13: Comprehensive Benchmark & Stress Tests
MIT License.