Leka
A low-latency C++20 price-time-priority limit order book and matching engine
▶ Replay viewer
Loading...
Searching...
No Matches
price_level.hpp
1#ifndef PRICE_LEVEL_HPP
2#define PRICE_LEVEL_HPP
3#include "lob/types/price.hpp"
4#include "lob/order/order.hpp"
5#include "lob/types/quantity.hpp"
6#include <cstddef>
7
8namespace lob {
9/**
10 * @brief Maintains FIFO resting orders at one price.
11 *
12 * Orders are linked intrusively, so appending and removing a known order are
13 * constant-time operations. The level also tracks order count and aggregate
14 * remaining quantity.
15 */
17 private:
18 Price price;
19 Order* headOrder{nullptr};
20 Order* tailOrder{nullptr};
21
22 std::size_t count{0}; // Counts of orders we currently have - init at 0
23
24 Quantity totalQuantity{0}; // Total quantity of orders at this price level - init at 0
25
26 public:
27 /** Creates an empty level for a single price. */
28 explicit PriceLevel(Price price) : price(price) {}
29
30 /** Returns the level price. */
31 Price getPrice() const { return price; }
32 /** Returns the first resting order, or nullptr when empty. */
33 Order* getHeadOrder() const { return headOrder; }
34 /** Returns the last resting order, or nullptr when empty. */
35 Order* getTailOrder() const { return tailOrder; }
36 /** Returns the number of resting orders. */
37 std::size_t getOrderCount() const { return count; }
38 /** Returns the aggregate remaining quantity. */
39 Quantity getTotalQuantity() const { return totalQuantity; }
40
41 /** Appends an order to the FIFO and updates aggregate state. */
42 void addOrder(Order* order);
43 /** Unlinks an order and updates aggregate state. */
44 void removeOrder(Order* order);
45
46 /** Decreases aggregate quantity after a partial execution. */
47 void reduceTotalQuantity(Quantity quantity);
48
49 /** Returns true when no orders are resting at this price. */
50 bool isEmpty() const;
51};
52} // namespace lob
53#endif // PRICE_LEVEL_HPP
Represents a resting or incoming order and its lifecycle state.
Definition order.hpp:17
PriceLevel(Price price)
Creates an empty level for a single price.
Order * getTailOrder() const
Returns the last resting order, or nullptr when empty.
void reduceTotalQuantity(Quantity quantity)
Decreases aggregate quantity after a partial execution.
Price getPrice() const
Returns the level price.
Order * getHeadOrder() const
Returns the first resting order, or nullptr when empty.
std::size_t getOrderCount() const
Returns the number of resting orders.
void removeOrder(Order *order)
Unlinks an order and updates aggregate state.
bool isEmpty() const
Returns true when no orders are resting at this price.
void addOrder(Order *order)
Appends an order to the FIFO and updates aggregate state.
Quantity getTotalQuantity() const
Returns the aggregate remaining quantity.
Type-safe nonzero price value used for price ordering.
Definition price.hpp:9
Type-safe unsigned order quantity; zero represents a filled state.
Definition quantity.hpp:8