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).
Order.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include "OrderType.hpp"
13 #include "Side.hpp"
14 #include <cstdint>
15 #include <stdexcept>
16 #include <format>
17 #include <list>
18 #include <memory>
19 
20 #include "Usings.hpp"
21 #include "Constants.hpp"
22 
31 class Order {
32 private:
33  OrderType _type;
34  OrderId _id;
35  Side _side;
36  Price _price;
37  Quantity _quantity;
38  Quantity _initialQty;
39  Quantity _remainingQty;
40 
41 public:
54  Order(OrderType type, OrderId id, Side side, Price price, Quantity qty)
55  : _type{ type }, _id{ id }, _side{ side }, _price{ price }, _quantity{ qty }, _initialQty{ qty }, _remainingQty{ qty } {}
56 
67  Order(OrderId orderId, Side side, Quantity quantity)
68  : Order(OrderType::Market, orderId, side, Constants::InvalidPrice, quantity) {}
69 
74  OrderId getOrderId() const;
75 
80  OrderType getOrderType() const;
81 
86  Side getSide() const;
87 
92  Price getPrice() const;
93 
101  Quantity getInitialQty() const;
102 
110  Quantity getQty() const;
111 
119  Quantity getRemainingQty() const;
120 
128  Quantity getFilledQty() const;
129 
134  bool isFilled() const;
135 
145  void Fill(Quantity qty);
146 
156  void toGoodTillCancel(Price price);
157 };
158 
163 using OrderPtr = std::shared_ptr<Order>;
164 
172 using OrderPtrs = std::list<OrderPtr>;
Defines the OrderType enum and related utility functions for handling different order types.
OrderType
Specifies the different types of orders that can be used in a trading system.
Definition: OrderType.hpp:18
std::shared_ptr< Order > OrderPtr
A shared pointer to an Order object.
Definition: Order.hpp:163
std::list< OrderPtr > OrderPtrs
A list of shared pointers to Order objects.
Definition: Order.hpp:172
Defines the Side enum for representing order sides (buy or sell) and utility functions.
Side
Represents the side of an order in a trading system (either buy or sell).
Definition: Side.hpp:16
Defines type aliases commonly used in the trading system.
std::int32_t Price
Represents the price of an order or trade.
Definition: Usings.hpp:21
std::uint32_t Quantity
Represents the quantity or volume of assets in an order or trade.
Definition: Usings.hpp:29
std::uint64_t OrderId
Represents a unique identifier for an order.
Definition: Usings.hpp:37
Represents a trading order with attributes and functionality to manage its state.
Definition: Order.hpp:31
Order(OrderType type, OrderId id, Side side, Price price, Quantity qty)
Constructs an order with specified type, ID, side, price, and quantity.
Definition: Order.hpp:54
OrderType getOrderType() const
Retrieves the type of the order (e.g., Market, GoodTillCancel).
Definition: Order.cpp:21
Side getSide() const
Retrieves the side of the order (Buy or Sell).
Definition: Order.cpp:27
Quantity getQty() const
Retrieves the current quantity of the order.
Definition: Order.cpp:51
Quantity getFilledQty() const
Retrieves the filled quantity of the order.
Definition: Order.cpp:69
Quantity getRemainingQty() const
Retrieves the remaining quantity of the order.
Definition: Order.cpp:60
OrderId getOrderId() const
Retrieves the unique ID of the order.
Definition: Order.cpp:15
void Fill(Quantity qty)
Fills the order by a specified quantity.
Definition: Order.cpp:86
bool isFilled() const
Checks if the order is fully filled.
Definition: Order.cpp:75
Order(OrderId orderId, Side side, Quantity quantity)
Constructs a market order with specified ID, side, and quantity.
Definition: Order.hpp:67
Quantity getInitialQty() const
Retrieves the initial quantity of the order.
Definition: Order.cpp:42
void toGoodTillCancel(Price price)
Converts a market order to a Good Till Cancel order with a specified price.
Definition: Order.cpp:102
Price getPrice() const
Retrieves the price of the order.
Definition: Order.cpp:33
Holds application-wide constants for common values.
Definition: Constants.hpp:21