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).
|
Represents a trading order with attributes and functionality to manage its state. More...
#include <Order.hpp>
Public Member Functions | |
Order (OrderType type, OrderId id, Side side, Price price, Quantity qty) | |
Constructs an order with specified type, ID, side, price, and quantity. More... | |
Order (OrderId orderId, Side side, Quantity quantity) | |
Constructs a market order with specified ID, side, and quantity. More... | |
OrderId | getOrderId () const |
Retrieves the unique ID of the order. More... | |
OrderType | getOrderType () const |
Retrieves the type of the order (e.g., Market, GoodTillCancel). More... | |
Side | getSide () const |
Retrieves the side of the order (Buy or Sell). More... | |
Price | getPrice () const |
Retrieves the price of the order. More... | |
Quantity | getInitialQty () const |
Retrieves the initial quantity of the order. More... | |
Quantity | getQty () const |
Retrieves the current quantity of the order. More... | |
Quantity | getRemainingQty () const |
Retrieves the remaining quantity of the order. More... | |
Quantity | getFilledQty () const |
Retrieves the filled quantity of the order. More... | |
bool | isFilled () const |
Checks if the order is fully filled. More... | |
void | Fill (Quantity qty) |
Fills the order by a specified quantity. More... | |
void | toGoodTillCancel (Price price) |
Converts a market order to a Good Till Cancel order with a specified price. More... | |
Represents a trading order with attributes and functionality to manage its state.
The Order class stores details of an order such as its type, ID, side (buy/sell), price, and quantities (initial, remaining, and filled). It provides methods for retrieving these details, filling the order, and adjusting its state.
Constructs an order with specified type, ID, side, price, and quantity.
Initializes an order with the specified attributes and sets the initial and remaining quantities to the specified quantity.
type | The type of the order (e.g., Market, GoodTillCancel). |
id | The unique identifier for the order. |
side | The side of the order (Buy or Sell). |
price | The price of the order. |
qty | The quantity of the order. |
Constructs a market order with specified ID, side, and quantity.
This constructor initializes a market order with the specified ID, side, and quantity, setting the price to an invalid state.
orderId | The unique identifier for the order. |
side | The side of the order (Buy or Sell). |
quantity | The quantity of the order. |
void Order::Fill | ( | Quantity | qty | ) |
Fills the order by a specified quantity.
Reduces the remaining quantity by the specified amount. If the quantity exceeds the remaining quantity, an exception is thrown.
qty | The quantity by which to fill the order. |
std::logic_error | if the specified quantity exceeds the remaining quantity. |
Quantity Order::getFilledQty | ( | ) | const |
Retrieves the filled quantity of the order.
This represents the difference between the initial quantity and the remaining quantity.
Quantity Order::getInitialQty | ( | ) | const |
Retrieves the initial quantity of the order.
This represents the original quantity specified when the order was created.
OrderId Order::getOrderId | ( | ) | const |
Retrieves the unique ID of the order.
OrderType Order::getOrderType | ( | ) | const |
Retrieves the type of the order (e.g., Market, GoodTillCancel).
Price Order::getPrice | ( | ) | const |
Retrieves the price of the order.
Quantity Order::getQty | ( | ) | const |
Retrieves the current quantity of the order.
This value may change if the order is partially filled.
Quantity Order::getRemainingQty | ( | ) | const |
Retrieves the remaining quantity of the order.
This represents the unfilled portion of the order.
Side Order::getSide | ( | ) | const |
Retrieves the side of the order (Buy or Sell).
bool Order::isFilled | ( | ) | const |
Checks if the order is fully filled.
void Order::toGoodTillCancel | ( | Price | price | ) |
Converts a market order to a Good Till Cancel order with a specified price.
Changes the order type to GoodTillCancel and sets the price. Only market orders can be converted; otherwise, an exception is thrown.
price | The price to set for the Good Till Cancel order. |
std::logic_error | if the order is not a market order. |