Orderbook Simulation
OrderbookSim is a C++ application simulating a financial market order book. It efficiently manages and matches buy and sell orders while calculating the Volume-Weighted Average Price (VWAP).
|
Manages and matches orders in a trading environment. More...
#include <Orderbook.hpp>
Public Member Functions | |
Orderbook () | |
Default constructor, initializes the Good For Day order pruning thread. More... | |
Orderbook (const Orderbook &)=delete | |
void | operator= (const Orderbook &)=delete |
Orderbook (Orderbook &&)=delete | |
void | operator= (Orderbook &&)=delete |
~Orderbook () | |
Destructor, joins the pruning thread and signals shutdown. More... | |
void | changeExecutionType (int type) |
Changes the execution type for order matching. More... | |
Trades | addOrder (OrderPtr order) |
Adds an order to the orderbook. More... | |
Trades | addOrder (OrderType type, Side side, Price price, Quantity qty) |
Adds a new order to the orderbook with specified parameters. More... | |
Trades | addOrder (OrderType type, OrderId orderId, Side side, Price price, Quantity qty) |
Adds a new order with a specified ID. More... | |
void | addOrderViaPython (int type, int id, int side, int price, int qty) |
Adds an order to the orderbook via Python interface. More... | |
void | CancelOrder (OrderId orderId) |
Cancels an order by its ID. More... | |
Trades | ModifyOrder (OrderModify order) |
Modifies an existing order. More... | |
void | setPriceScale (Price _price) |
Sets the price scale for the orderbook. More... | |
Price | getPriceScale () |
Retrieves the current price scale of the orderbook. More... | |
void | printAllOrders () |
Prints all orders and orderbook details. More... | |
void | saveToJson (const std::string &buyfilename="BuyHistory.json", const std::string &sellfilename="SellHistory.json", const std::string &purchasefilename="PurchaseHistory.json", const std::string &buyLivefilename="BuyLiveHistory.json", const std::string &sellLivefilename="SellLiveHistory.json") |
Saves orderbook data to JSON files. More... | |
std::size_t | Size () const |
Retrieves the number of orders in the orderbook. More... | |
OrderbookLevelInfos | getOrderInfos () const |
Retrieves aggregated orderbook level information. More... | |
void | EndOfDay () |
Handles end-of-day processing for the orderbook. More... | |
Manages and matches orders in a trading environment.
The Orderbook class maintains separate collections for bids and asks, as well as provides functions for adding, canceling, modifying, and matching orders. It also includes features for managing Good For Day orders and saving the orderbook state to JSON.
|
inline |
Default constructor, initializes the Good For Day order pruning thread.
|
delete |
|
delete |
|
inline |
Destructor, joins the pruning thread and signals shutdown.
Adds an order to the orderbook.
order | The order to add. |
Adds the provided order to the orderbook, updates internal data structures, and attempts to match orders.
order | A shared pointer to the Order to add. |
Adds a new order with a specified ID.
Adds a new order to the orderbook with a specified ID.
type | The type of the order. |
orderId | The ID of the order. |
side | The side of the order (Buy or Sell). |
price | The price of the order. |
qty | The quantity of the order. |
Creates and adds a new order with the specified ID and parameters.
type | The type of the order. |
id | The ID of the order. |
side | The side of the order (Buy or Sell). |
price | The price of the order. |
qty | The quantity of the order. |
Adds a new order to the orderbook with specified parameters.
Adds a new order to the orderbook.
type | The type of the order. |
side | The side of the order (Buy or Sell). |
price | The price of the order. |
qty | The quantity of the order. |
Creates and adds a new order to the orderbook with the specified parameters.
type | The type of the order. |
side | The side of the order (Buy or Sell). |
price | The price of the order. |
qty | The quantity of the order. |
void Orderbook::addOrderViaPython | ( | int | type, |
int | id, | ||
int | side, | ||
int | price, | ||
int | qty | ||
) |
Adds an order to the orderbook via Python interface.
type | The type of the order (as integer). |
id | The ID of the order. |
side | The side of the order (1 for Buy, 2 for Sell). |
price | The price of the order. |
qty | The quantity of the order. |
Exposed to Python via Pybind11, allows adding orders from Python code.
type | The type of the order (as integer). |
id | The ID of the order. |
side | The side of the order (1 for Buy, 2 for Sell). |
price | The price of the order. |
qty | The quantity of the order. |
void Orderbook::CancelOrder | ( | OrderId | orderId | ) |
Cancels an order by its ID.
orderId | The ID of the order to cancel. |
Public interface to cancel an order.
orderId | The ID of the order to cancel. |
void Orderbook::changeExecutionType | ( | int | type | ) |
Changes the execution type for order matching.
type | The execution type (0: BuyersPrice, 1: SellersPrice, 2: MidPrice). |
Adjusts how the execution price is determined during order matching.
type | The execution type (0: BuyersPrice, 1: SellersPrice, 2: MidPrice). |
void Orderbook::EndOfDay | ( | ) |
Handles end-of-day processing for the orderbook.
Cancels GoodForDay orders and cleans up orders and order entries.
OrderbookLevelInfos Orderbook::getOrderInfos | ( | ) | const |
Retrieves aggregated orderbook level information.
Provides information about the bid and ask levels in the orderbook, including prices and quantities.
Price Orderbook::getPriceScale | ( | ) |
Retrieves the current price scale of the orderbook.
Trades Orderbook::ModifyOrder | ( | OrderModify | order | ) |
Modifies an existing order.
order | The OrderModify object containing new order details. |
Replaces the existing order with a new one based on the modification details.
order | The OrderModify object containing new order details. |
|
delete |
|
delete |
void Orderbook::printAllOrders | ( | ) |
Prints all orders and orderbook details.
Outputs order histories and statistics to the console.
void Orderbook::saveToJson | ( | const std::string & | buyfilename = "BuyHistory.json" , |
const std::string & | sellfilename = "SellHistory.json" , |
||
const std::string & | purchasefilename = "PurchaseHistory.json" , |
||
const std::string & | buyLivefilename = "BuyLiveHistory.json" , |
||
const std::string & | sellLivefilename = "SellLiveHistory.json" |
||
) |
Saves orderbook data to JSON files.
Exports order histories and live orders to specified JSON files.
buyfilename | Filename for buy order history. |
sellfilename | Filename for sell order history. |
purchasefilename | Filename for purchase history. |
buyLivefilename | Filename for live buy orders. |
sellLivefilename | Filename for live sell orders. |
void Orderbook::setPriceScale | ( | Price | _price | ) |
Sets the price scale for the orderbook.
_price | The new price scale to set. |
Adjusts the price scale used in the orderbook's internal calculations.
_price | The new price scale to set. |
std::size_t Orderbook::Size | ( | ) | const |
Retrieves the number of orders in the orderbook.