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).
Public Member Functions | List of all members
OrderDetailHistory Class Reference

Manages the history of orders and tracks live orders in the orderbook. More...

#include <OrderDetailHistory.hpp>

Public Member Functions

 OrderDetailHistory ()
 Default constructor that initializes the neural network with a predefined topology. More...
 
int buyHistorySize () const
 Returns the size of the buy history. More...
 
int sellHistorySize () const
 Returns the size of the sell history. More...
 
int purchaseHistorySize () const
 Returns the size of the purchase history. More...
 
void updateNeutralNetwork (Price price, Quantity quantity)
 Updates the neural network with the latest order price and quantity data. More...
 
void addOrderToHistory (const OrderType type, const OrderId id, const Side side, const Price price, const Quantity qty)
 Adds an order to the appropriate history (buy or sell) based on its side. More...
 
void addOrderToPurchaseHistory (const Price price, const Quantity qty)
 Adds a new purchase order to the purchase history. More...
 
void saveHistoryToJson (const std::string &buyfilename, const std::string &sellfilename, const std::string &purchasefilename)
 Saves the buy, sell, and purchase histories to JSON files. More...
 
void saveHistoryToJson (const std::string &buyfilename="BuyHistory.json", const std::string &sellfilename="SellHistory.json", const std::string &purchasefilename="PurchaseHistory.json", const std::string &liveSellOrdersFilename="LiveSellHistory.json", const std::string &buySellOrdersFilename="LiveBuyHistory.json")
 Saves multiple histories including live orders to JSON files. More...
 
void removeMatchedOrder (const OrderId bidId, const OrderId askID)
 Removes matched orders by IDs from the live orders map. More...
 
void _printSellHistory ()
 Prints the sell history to the console. More...
 
void _printBuyHistory ()
 Prints the buy history to the console. More...
 
void _printPurchaseHistory ()
 Prints the purchase history to the console. More...
 
void _printLiveOrders ()
 Prints the live orders to the console. More...
 
Price getVWAP ()
 Calculates the Volume-Weighted Average Price (VWAP) of all purchases. More...
 
Price getVWAP (int n)
 Calculates the VWAP of the last n purchases. More...
 
Price getPrediction ()
 Retrieves the last prediction from the neural network. More...
 
std::unordered_map< OrderId, OrderDetailgetLiveOrders ()
 Retrieves a map of all currently live orders. More...
 
void deleteALiveOrder (OrderId id)
 Deletes a live order by ID. More...
 

Detailed Description

Manages the history of orders and tracks live orders in the orderbook.

The OrderDetailHistory class stores order details, provides methods to save and retrieve order data, and uses a neural network to predict future prices.

Constructor & Destructor Documentation

◆ OrderDetailHistory()

OrderDetailHistory::OrderDetailHistory ( )
inline

Default constructor that initializes the neural network with a predefined topology.

Member Function Documentation

◆ _printBuyHistory()

void OrderDetailHistory::_printBuyHistory ( )

Prints the buy history to the console.

Prints the buy history.

◆ _printLiveOrders()

void OrderDetailHistory::_printLiveOrders ( )

Prints the live orders to the console.

◆ _printPurchaseHistory()

void OrderDetailHistory::_printPurchaseHistory ( )

Prints the purchase history to the console.

Prints the purchase history.

◆ _printSellHistory()

void OrderDetailHistory::_printSellHistory ( )

Prints the sell history to the console.

Prints the sell history.

◆ addOrderToHistory()

void OrderDetailHistory::addOrderToHistory ( const OrderType  type,
const OrderId  id,
const Side  side,
const Price  price,
const Quantity  qty 
)

Adds an order to the appropriate history (buy or sell) based on its side.

Parameters
typeThe type of the order.
idThe unique identifier of the order.
sideThe side of the order (Buy or Sell).
priceThe price of the order.
qtyThe quantity of the order.

◆ addOrderToPurchaseHistory()

void OrderDetailHistory::addOrderToPurchaseHistory ( const Price  price,
const Quantity  qty 
)

Adds a new purchase order to the purchase history.

Adds a new purchase to the purchase history.

Parameters
priceThe price at which the order was purchased.
qtyThe quantity of the order.

◆ buyHistorySize()

int OrderDetailHistory::buyHistorySize ( ) const

Returns the size of the buy history.

Returns
The number of buy orders in the history.

◆ deleteALiveOrder()

void OrderDetailHistory::deleteALiveOrder ( OrderId  id)

Deletes a live order by ID.

Deletes a live order by its ID.

Parameters
idThe ID of the order to delete.

◆ getLiveOrders()

std::unordered_map< OrderId, OrderDetail > OrderDetailHistory::getLiveOrders ( )

Retrieves a map of all currently live orders.

Returns a copy of the live orders map.

Returns
An unordered_map of live orders.
A map of live orders indexed by order ID.

◆ getPrediction()

Price OrderDetailHistory::getPrediction ( )

Retrieves the last prediction from the neural network.

Retrieves the current VWAP price.

Returns
The predicted price.
The most recent prediction from the neural network.

◆ getVWAP() [1/2]

Price OrderDetailHistory::getVWAP ( )

Calculates the Volume-Weighted Average Price (VWAP) of all purchases.

Returns
The VWAP of all purchases.

◆ getVWAP() [2/2]

Price OrderDetailHistory::getVWAP ( int  n)

Calculates the VWAP of the last n purchases.

Calculates the VWAP for the last n purchases.

Returns
The VWAP of the last n purchases.
Parameters
nThe number of recent purchases to include in the calculation.
Returns
The VWAP of the last n purchases.

◆ purchaseHistorySize()

int OrderDetailHistory::purchaseHistorySize ( ) const

Returns the size of the purchase history.

Returns
The number of matched purchase orders in the history.

◆ removeMatchedOrder()

void OrderDetailHistory::removeMatchedOrder ( const OrderId  bidId,
const OrderId  askId 
)

Removes matched orders by IDs from the live orders map.

Removes a matched order from the live order map.

Parameters
bidIdThe unique identifier of the buy order.
askIdThe unique identifier of the sell order.

◆ saveHistoryToJson() [1/2]

void OrderDetailHistory::saveHistoryToJson ( const std::string &  buyfilename,
const std::string &  sellfilename,
const std::string &  purchasefilename 
)

Saves the buy, sell, and purchase histories to JSON files.

◆ saveHistoryToJson() [2/2]

void OrderDetailHistory::saveHistoryToJson ( const std::string &  buyfilename = "BuyHistory.json",
const std::string &  sellfilename = "SellHistory.json",
const std::string &  purchasefilename = "PurchaseHistory.json",
const std::string &  liveSellOrdersFilename = "LiveSellHistory.json",
const std::string &  buySellOrdersFilename = "LiveBuyHistory.json" 
)

Saves multiple histories including live orders to JSON files.

◆ sellHistorySize()

int OrderDetailHistory::sellHistorySize ( ) const

Returns the size of the sell history.

Returns
The number of sell orders in the history.

◆ updateNeutralNetwork()

void OrderDetailHistory::updateNeutralNetwork ( Price  price,
Quantity  quantity 
)

Updates the neural network with the latest order price and quantity data.

Updates the neural network with new price and quantity data.

Parameters
priceThe price of the latest matched order.
quantityThe quantity of the latest matched order.

The documentation for this class was generated from the following files: