Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Production-Grade Order Management System (OMS) in C++20

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.


🌟 Key Features

  • Strict Order State Machine: Immutable state transitions governed by an OrderStateMachine gatekeeper. Prevents invalid state shifts (e.g. FILLED -> LIVE or 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_clock nanosecond timing, [[nodiscard]], and noexcept.
  • Zero Allocation Hot Paths: Pass-by-reference design to eliminate heap allocation overhead during order transitions.

📁 Architecture & Components

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

🛠️ Build and Run Instructions

Prerequisites

  • C++20 compatible compiler (clang++ $\ge 12$ or g++ $\ge 10$)
  • CMake $\ge 3.20$ (optional, direct build supported)

Option 1: Direct Build (Fastest)

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_machine

Option 2: Using CMake

mkdir -p build
cd build
cmake ..
make
./test_state_machine

🧪 Test Suite Coverage

  • ✅ 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

📜 Roadmap

  • 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

📄 License

MIT License.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages