Skip to content

kvyns/cpp-orderbook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Order Book

This project is a C++ implementation of a financial exchange order book. It showcases a high-performance matching engine with features like limit/market orders, cancel/modify, and market data analytics.

Features

  • Price-Time Priority: Orders are matched based on price, then time of submission (FIFO).
  • Order Types: Supports limit and market orders.
  • Operations:
    • Submit new orders
    • Cancel existing orders
    • Modify order price/quantity
  • Market Data:
    • Best bid/ask
    • Spread
    • Mid-price
    • Order book depth
  • Analytics:
    • Trade volume and count
    • Order imbalance
    • Price level heatmap
  • Multithreading: A threaded exchange model demonstrates concurrent order submission and matching.

Phases

The main.cpp file demonstrates the project's functionality in several phases:

  • Phase 1: Core Order Book: Demonstrates the fundamental features of the OrderBook class, including submitting limit and market orders, canceling and modifying orders, and retrieving basic market data.
  • Phase 3: Exchange Simulation: The Exchange class simulates a trading environment with a high volume of orders, measuring performance metrics like throughput and latency.
  • Phase 4: Multithreading: The ThreadedExchange class introduces a multi-threaded architecture with a producer thread submitting orders and a consumer thread matching them.
  • Phase 5: Analytics: This phase showcases the Analytics class, which provides insights into market data, such as order book depth, trade statistics, and order imbalance.

Building and Running

To build the project, you can use the provided commands:

g++ -std=c++20 -O2 -I. main.cpp src/OrderBook.cpp src/Exchange.cpp src/ThreadedExchange.cpp -pthread -static -o orderbook.exe

This will create executable: orderbook.

  • ./orderbook: Runs the main program (main.cpp) which executes all the phases.
g++ -std=c++20 -O2 -I. cli.cpp src/OrderBook.cpp src/Exchange.cpp src/ThreadedExchange.cpp -pthread -static -o cli.exe

This will create executable: cli.

  • ./cli: Provides a command-line interface for interacting with the order book.

CLI Usage

The CLI allows you to interact with the order book in real-time. Here are some of the available commands:

  • SUB <side> <price> <qty>: Submit a limit order.
  • MARKET <side> <qty>: Submit a market order.
  • CANCEL <id>: Cancel an order.
  • MODIFY <id> <new_price> <new_qty>: Modify an order.
  • PRINT: Print the current state of the order book.
  • HELP: Display a list of available commands.
  • EXIT: Exit the CLI.

About

High-performance C++20 exchange matching engine with price-time priority, lock-free multithreading, market data analytics (VWAP/TWAP), and 1.8M+ orders/sec throughput

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages