21 #include <unordered_map>
24 #include <condition_variable>
44 OrderPtrs::iterator _location;
51 enum class ExecutionTypes {
76 std::map<Price, OrderPtrs, std::greater<Price>> _asks;
77 std::map<Price, OrderPtrs, std::less<Price>> _bids;
78 std::unordered_map<OrderId, OrderEntry> _orders;
79 std::unordered_map<Price, LevelData> _data;
81 mutable std::mutex _ordersMutex;
82 std::thread _ordersPruneThread;
83 std::condition_variable _shutdownConditionVariable;
84 std::atomic<bool> _shutdown{
false };
86 ExecutionTypes _executionType = ExecutionTypes::BuyersPrice;
90 bool canMatch(
Side side,
Price price)
const;
92 void CancelOrders(
OrderIds orderIds);
93 void CancelOrderInternal(
OrderId orderId);
96 void onOrderCanceleld(
OrderPtr order);
98 void onOrderMatchedWithHistoryUpdate(
Price price,
Quantity quantity,
bool isFullyFilled,
Price purchasePrice);
99 void onOrderMatched(
Price price,
Quantity quantity,
bool isFullyFilled);
100 void UpdateLevelData(
Price price,
Quantity quantity, LevelData::Action action);
104 void PruneGoodForDayOrders();
110 Orderbook() : _ordersPruneThread{ [this] { PruneGoodForDayOrders(); } } {}
122 _shutdown.store(
true, std::memory_order_release);
123 _shutdownConditionVariable.notify_one();
124 _ordersPruneThread.join();
132 void changeExecutionType(
int type);
174 void addOrderViaPython(
int type,
int id,
int side,
int price,
int qty);
181 void CancelOrder(
OrderId orderId);
196 void setPriceScale(
Price _price);
203 Price getPriceScale();
208 void printAllOrders();
221 void saveToJson(
const std::string& buyfilename =
"BuyHistory.json",
const std::string& sellfilename =
"SellHistory.json",
const std::string& purchasefilename =
"PurchaseHistory.json",
const std::string& buyLivefilename =
"BuyLiveHistory.json",
const std::string& sellLivefilename =
"SellLiveHistory.json");
228 std::size_t Size()
const;
Declares the OrderDetailHistory class for managing order histories and live orders.
Defines the OrderModify class, which encapsulates modifications to an order's details.
OrderType
Specifies the different types of orders that can be used in a trading system.
Definition: OrderType.hpp:18
Defines the Order class and related types for managing orders in a trading system.
std::shared_ptr< Order > OrderPtr
A shared pointer to an Order object.
Definition: Order.hpp:163
Defines the OrderbookLevelInfos class for managing bid and ask levels in an orderbook.
Side
Represents the side of an order in a trading system (either buy or sell).
Definition: Side.hpp:16
Defines the Trade class, representing a completed trade with bid and ask details.
std::vector< Trade > Trades
A type alias for a collection of Trade objects.
Definition: Trade.hpp:64
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::vector< OrderId > OrderIds
A collection of unique order identifiers.
Definition: Usings.hpp:45
std::uint64_t OrderId
Represents a unique identifier for an order.
Definition: Usings.hpp:37
Manages the history of orders and tracks live orders in the orderbook.
Definition: OrderDetailHistory.hpp:27
Represents a modification to an existing order.
Definition: OrderModify.hpp:23
Holds the bid and ask levels for an orderbook.
Definition: OrderbookLevelInfos.hpp:21
Manages and matches orders in a trading environment.
Definition: Orderbook.hpp:36
Orderbook()
Default constructor, initializes the Good For Day order pruning thread.
Definition: Orderbook.hpp:110
void operator=(const Orderbook &)=delete
Orderbook(Orderbook &&)=delete
void operator=(Orderbook &&)=delete
~Orderbook()
Destructor, joins the pruning thread and signals shutdown.
Definition: Orderbook.hpp:121
Orderbook(const Orderbook &)=delete
Definition: addOrder.py:1