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.
- 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.
The main.cpp file demonstrates the project's functionality in several phases:
- Phase 1: Core Order Book: Demonstrates the fundamental features of the
OrderBookclass, including submitting limit and market orders, canceling and modifying orders, and retrieving basic market data. - Phase 3: Exchange Simulation: The
Exchangeclass simulates a trading environment with a high volume of orders, measuring performance metrics like throughput and latency. - Phase 4: Multithreading: The
ThreadedExchangeclass introduces a multi-threaded architecture with a producer thread submitting orders and a consumer thread matching them. - Phase 5: Analytics: This phase showcases the
Analyticsclass, which provides insights into market data, such as order book depth, trade statistics, and order imbalance.
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.exeThis 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.exeThis will create executable: cli.
./cli: Provides a command-line interface for interacting with the order book.
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.