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
Order Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Order() [1/2]

Order::Order ( OrderType  type,
OrderId  id,
Side  side,
Price  price,
Quantity  qty 
)
inline

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.

Parameters
typeThe type of the order (e.g., Market, GoodTillCancel).
idThe unique identifier for the order.
sideThe side of the order (Buy or Sell).
priceThe price of the order.
qtyThe quantity of the order.

◆ Order() [2/2]

Order::Order ( OrderId  orderId,
Side  side,
Quantity  quantity 
)
inline

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.

Parameters
orderIdThe unique identifier for the order.
sideThe side of the order (Buy or Sell).
quantityThe quantity of the order.

Member Function Documentation

◆ Fill()

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.

Parameters
qtyThe quantity by which to fill the order.
Exceptions
std::logic_errorif the specified quantity exceeds the remaining quantity.

◆ getFilledQty()

Quantity Order::getFilledQty ( ) const

Retrieves the filled quantity of the order.

This represents the difference between the initial quantity and the remaining quantity.

Returns
The quantity of the order that has been filled.

◆ getInitialQty()

Quantity Order::getInitialQty ( ) const

Retrieves the initial quantity of the order.

This represents the original quantity specified when the order was created.

Returns
The initial quantity of the order.

◆ getOrderId()

OrderId Order::getOrderId ( ) const

Retrieves the unique ID of the order.

Returns
The ID of the order.

◆ getOrderType()

OrderType Order::getOrderType ( ) const

Retrieves the type of the order (e.g., Market, GoodTillCancel).

Returns
The type of the order.

◆ getPrice()

Price Order::getPrice ( ) const

Retrieves the price of the order.

Returns
The price of the order.

◆ getQty()

Quantity Order::getQty ( ) const

Retrieves the current quantity of the order.

This value may change if the order is partially filled.

Returns
The current quantity of the order.

◆ getRemainingQty()

Quantity Order::getRemainingQty ( ) const

Retrieves the remaining quantity of the order.

This represents the unfilled portion of the order.

Returns
The remaining quantity of the order.

◆ getSide()

Side Order::getSide ( ) const

Retrieves the side of the order (Buy or Sell).

Returns
The side of the order.

◆ isFilled()

bool Order::isFilled ( ) const

Checks if the order is fully filled.

Returns
True if the order is fully filled, false otherwise.

◆ toGoodTillCancel()

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.

Parameters
priceThe price to set for the Good Till Cancel order.
Exceptions
std::logic_errorif the order is not a market order.

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