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).
MatchedOrderDetails.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <chrono>
12 #include <sstream> // For std::ostringstream
13 #include <iomanip> // For std::put_time
14 
15 #include "OrderType.hpp"
16 #include "Side.hpp"
17 #include "Usings.hpp"
18 #include "Constants.hpp"
19 
20 using timeChrono = std::chrono::system_clock::time_point;
21 
31 private:
32  Price _price;
33  Quantity _quantity;
34  timeChrono _time;
35 
36 public:
46  MatchedOrderDetail(Price price, Quantity qty) : _price{ price }, _quantity{ qty } {
47  _time = std::chrono::system_clock::now();
48  }
49 
54  Price getPrice() const { return _price; }
55 
60  Quantity getQuantity() const { return _quantity; }
61 
69  std::string getTime() const {
70  std::time_t timeT = std::chrono::system_clock::to_time_t(_time);
71  std::tm tm;
72  localtime_s(&tm, &timeT); // Use localtime_s instead of localtime for thread safety
73  std::ostringstream oss;
74  oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S");
75  return oss.str();
76  }
77 };
std::chrono::system_clock::time_point timeChrono
Definition: MatchedOrderDetails.hpp:20
Defines the OrderType enum and related utility functions for handling different order types.
Defines the Side enum for representing order sides (buy or sell) and utility functions.
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
Stores details of a matched order, including price, quantity, and time.
Definition: MatchedOrderDetails.hpp:30
std::string getTime() const
Retrieves the timestamp of when the order was matched as a formatted string.
Definition: MatchedOrderDetails.hpp:69
MatchedOrderDetail(Price price, Quantity qty)
Constructs a MatchedOrderDetail with specified price and quantity.
Definition: MatchedOrderDetails.hpp:46
Quantity getQuantity() const
Retrieves the quantity of the matched order.
Definition: MatchedOrderDetails.hpp:60
Price getPrice() const
Retrieves the price of the matched order.
Definition: MatchedOrderDetails.hpp:54