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 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, OrderDetail > | getLiveOrders () |
Retrieves a map of all currently live orders. More... | |
void | deleteALiveOrder (OrderId id) |
Deletes a live order by ID. More... | |
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.
|
inline |
Default constructor that initializes the neural network with a predefined topology.
void OrderDetailHistory::_printBuyHistory | ( | ) |
Prints the buy history to the console.
Prints the buy history.
void OrderDetailHistory::_printLiveOrders | ( | ) |
Prints the live orders to the console.
void OrderDetailHistory::_printPurchaseHistory | ( | ) |
Prints the purchase history to the console.
Prints the purchase history.
void OrderDetailHistory::_printSellHistory | ( | ) |
Prints the sell history to the console.
Prints the sell history.
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.
type | The type of the order. |
id | The unique identifier 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 purchase order to the purchase history.
Adds a new purchase to the purchase history.
price | The price at which the order was purchased. |
qty | The quantity of the order. |
int OrderDetailHistory::buyHistorySize | ( | ) | const |
Returns the size of the buy history.
void OrderDetailHistory::deleteALiveOrder | ( | OrderId | id | ) |
Deletes a live order by ID.
Deletes a live order by its ID.
id | The ID of the order to delete. |
std::unordered_map< OrderId, OrderDetail > OrderDetailHistory::getLiveOrders | ( | ) |
Retrieves a map of all currently live orders.
Returns a copy of the live orders map.
Price OrderDetailHistory::getPrediction | ( | ) |
Retrieves the last prediction from the neural network.
Retrieves the current VWAP price.
Price OrderDetailHistory::getVWAP | ( | ) |
Calculates the Volume-Weighted Average Price (VWAP) of all purchases.
Price OrderDetailHistory::getVWAP | ( | int | n | ) |
Calculates the VWAP of the last n
purchases.
Calculates the VWAP for the last n
purchases.
n
purchases.n | The number of recent purchases to include in the calculation. |
n
purchases. int OrderDetailHistory::purchaseHistorySize | ( | ) | const |
Returns the size of the purchase history.
Removes matched orders by IDs from the live orders map.
Removes a matched order from the live order map.
bidId | The unique identifier of the buy order. |
askId | The unique identifier of the sell order. |
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.
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.
int OrderDetailHistory::sellHistorySize | ( | ) | const |
Returns the size of the sell history.
Updates the neural network with the latest order price and quantity data.
Updates the neural network with new price and quantity data.
price | The price of the latest matched order. |
quantity | The quantity of the latest matched order. |