Skip to content

C++20 order book engine with Qt GUI for real-time trading simulation and automated market data processing

Notifications You must be signed in to change notification settings

a38062an/OrderBook

Repository files navigation

OrderBook

A high-performance C++ order matching engine with Qt6 GUI and SQLite persistence.

Build and Run

# Build setup
mkdir build && cd build
cmake ..
make

# Run GUI application
./OrderBookGUI

# Run tests
./test_orderbook

Database Population

Pre-populate the database with market scenarios for testing:

# Built-in scenarios
./populate_db --scenario normal    # Balanced market
./populate_db --scenario thin      # Wide spreads
./populate_db --scenario volatile  # Random prices

# Python-generated data
python3 scripts/data/populate_orderbook.py  # Generate CSV
./populate_db --csv data/csv/orderbook_scenario.csv

# Database management
./populate_db --clear              # Clear all orders
./populate_db --stats              # Show statistics

The GUI automatically loads pre-populated orders on startup.

Development Workflow

# Make changes to source files
# Then rebuild (only changed files recompile)
make && ./OrderBookGUI

# Run tests after changes
./test_orderbook

Project Structure

Core Implementation

  • src/core/ - Core orderbook engine and data structures
  • src/gui/ - Qt6 GUI application with real-time visualization
  • database/lib/ - SQLite database integration
  • database/tools/ - Database population utilities
  • scripts/data/ - Python data generation scripts
  • tests/ - Comprehensive stress tests and benchmarks

Build System

  • CMakeLists.txt - Build configuration creating orderbook_lib static library
  • build/ - Generated build files and executables

Tests

  • test/test_orderbook.cpp - Comprehensive test suite covering all functionality including:
    • Basic functionality (empty orderbook, single orders, multiple orders)
    • Order matching (exact match, partial fills, multiple matches, price/time priority)
    • Edge cases (zero quantity, large quantities, price boundaries, cancellation)
    • Fill-or-Kill orders (successful execution and rejection)
    • Performance tests (many orders)

Architecture

Order Matching

  • Price-time priority matching algorithm
  • Partial fill support with remaining quantity tracking
  • Automatic trade generation for matched orders
  • Fill-or-Kill (FOK) order type support

Data Structures

  • std::map<Price, std::list<OrderPointer>> for bid/ask price levels
  • std::unordered_map<OrderId, OrderEntry> for O(1) order lookup
  • FIFO ordering within price levels using std::list

Key Classes

  • Order - Individual order with fill tracking
  • Orderbook - Main matching engine
  • OrderbookLevelInfos - Price level aggregation for display

Requirements

  • C++20 compatible compiler
  • CMake 3.20 or higher

Documentation

About

C++20 order book engine with Qt GUI for real-time trading simulation and automated market data processing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published