TradeSim is a C++ simulation of a stock exchange. It supports order types, including market and limit orders, and employs a multithreaded approach for efficient order processing.
- Order Types: Supports MARKET_BUY, MARKET_SELL, LIMIT_BUY, LIMIT_SELL, and CANCEL.
- Comprehensive Logging: Detailed logs for each step of order processing.
- Order Matching: FIFO and price-time priority matching algorithms.
- CMake: Ensure CMake is installed on your system.
- Boost Library: Install Boost libraries for UUID generation.
- C++17 Compiler: Ensure you have a C++17 compatible compiler (e.g., GCC, Clang).
sudo apt-get update
sudo apt-get install cmake libboost-all-dev build-essential
brew install cmake boost
- Install CMake and Boost, ensure they are added to your system PATH.
git clone https://github.com/nilesh05apr/TradeSim.git
cd TradeSim
mkdir build
cd build
cmake ..
make
./TradeSim
ExchangeSim/
|-- Utils/
| |-- Utils.h
| |-- Utils.cpp
|-- Exchange/
| |-- Exchange.h
| |-- Exchange.cpp
|-- Order/
| |-- Order.h
|-- MatchOrder/
| |-- MatchOrder.h
| |-- MatchOrder.cpp
|-- OrderBook/
| |-- OrderBook.h
| |-- OrderBook.cpp
|-- Stock/
| |-- Stock.h
| |-- Stock.cpp
|-- main.cpp
|-- CMakeLists.txt
Edit main.cpp to list a stock with the following code:
exchange.listStock("AAPL", "Apple Inc.", 150.0, 1000000);
Add code in main.cpp to place orders:
Order::Order buyOrder1("AAPL", Order::OrderType::LIMIT_BUY, 150.0, 10);
Order::Order sellOrder1("AAPL", Order::OrderType::LIMIT_SELL, 150.0, 5);
Order::Order marketBuyOrder("AAPL", Order::OrderType::MARKET_BUY, 0.0, 15);
exchange.placeOrder(buyOrder1);
exchange.placeOrder(sellOrder1);
exchange.placeOrder(marketBuyOrder);
exchange.getOrderBook("AAPL");
exchange.getTradeHistory("AAPL");
Ensure to stop the exchange to gracefully terminate threads:
exchange.stop();
This project is licensed under the MIT License. See the LICENSE file for details.