Slick OrderBook 1.1.0
High-Performance C++23 OrderBook Library
Loading...
Searching...
No Matches
price_level_l3.hpp
Go to the documentation of this file.
1// Copyright 2026 Slick Quant
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
10
12
16 Price price; // Price level
17 IntrusiveList<Order> orders; // Orders at this price (sorted by priority)
18 Quantity total_quantity; // Cached total quantity for fast L2 aggregation
19
20 explicit PriceLevelL3(Price p) noexcept
21 : price(p), orders(), total_quantity(0) {}
22
24 [[nodiscard]] Quantity getTotalQuantity() const noexcept {
25 return total_quantity;
26 }
27
29 [[nodiscard]] std::size_t orderCount() const noexcept {
30 return orders.size();
31 }
32
34 [[nodiscard]] bool isEmpty() const noexcept {
35 return orders.empty();
36 }
37
39 [[nodiscard]] Order* getBestOrder() noexcept {
40 return orders.empty() ? nullptr : orders.front();
41 }
42
43 [[nodiscard]] const Order* getBestOrder() const noexcept {
44 return orders.empty() ? nullptr : orders.front();
45 }
46
48 void insertOrder(Order* order) noexcept {
49 // Insert in priority order (lower priority value = higher priority)
50 auto it = orders.begin();
51 while (it != orders.end() && it->priority <= order->priority) {
52 ++it;
53 }
54
55 if (it == orders.end()) {
56 orders.push_back(order);
57 } else {
58 orders.insert_before(&(*it), order);
59 }
60
61 total_quantity += order->quantity;
62 }
63
65 void removeOrder(Order* order) noexcept {
66 total_quantity -= order->quantity;
67 orders.erase(order);
68 }
69
71 void updateOrderQuantity(Quantity old_quantity, Quantity new_quantity) noexcept {
72 total_quantity = total_quantity - old_quantity + new_quantity;
73 }
74
76 [[nodiscard]] constexpr bool operator==(const PriceLevelL3& other) const noexcept {
77 return price == other.price;
78 }
79
80 [[nodiscard]] constexpr bool operator!=(const PriceLevelL3& other) const noexcept {
81 return price != other.price;
82 }
83
84 [[nodiscard]] constexpr bool operator<(const PriceLevelL3& other) const noexcept {
85 return price < other.price;
86 }
87
88 [[nodiscard]] constexpr bool operator>(const PriceLevelL3& other) const noexcept {
89 return price > other.price;
90 }
91};
92
95 [[nodiscard]] constexpr bool operator()(const PriceLevelL3& a, const PriceLevelL3& b) const noexcept {
96 return a.price > b.price; // Descending: highest bid first
97 }
98
99 [[nodiscard]] constexpr bool operator()(Price a, const PriceLevelL3& b) const noexcept {
100 return a > b.price;
101 }
102
103 [[nodiscard]] constexpr bool operator()(const PriceLevelL3& a, Price b) const noexcept {
104 return a.price > b;
105 }
106
107 [[nodiscard]] constexpr bool operator()(Price a, Price b) const noexcept {
108 return a > b;
109 }
110};
111
114 [[nodiscard]] constexpr bool operator()(const PriceLevelL3& a, const PriceLevelL3& b) const noexcept {
115 return a.price < b.price; // Ascending: lowest ask first
116 }
117
118 [[nodiscard]] constexpr bool operator()(Price a, const PriceLevelL3& b) const noexcept {
119 return a < b.price;
120 }
121
122 [[nodiscard]] constexpr bool operator()(const PriceLevelL3& a, Price b) const noexcept {
123 return a.price < b;
124 }
125
126 [[nodiscard]] constexpr bool operator()(Price a, Price b) const noexcept {
127 return a < b;
128 }
129};
130
Intrusive doubly-linked list for zero-allocation order management.
constexpr pointer front() noexcept
Get front element.
constexpr iterator end() noexcept
constexpr void erase(T *node) noexcept
Remove specific element from list O(1) operation - no search required.
constexpr size_type size() const noexcept
Get number of elements.
constexpr bool empty() const noexcept
Check if list is empty.
constexpr iterator begin() noexcept
Iterators.
constexpr void push_back(T *node) noexcept
Add element to back (oldest order, FIFO time priority)
constexpr void insert_before(T *pos, T *node) noexcept
Insert element before given position O(1) operation.
#define SLICK_DETAIL_NAMESPACE_BEGIN
Definition config.hpp:129
#define SLICK_DETAIL_NAMESPACE_END
Definition config.hpp:130
int64_t Quantity
Quantity type - volume or size.
Definition types.hpp:21
int64_t Price
Price type - fixed-point representation Example: For 4 decimal places, price = actual_price * 10000 T...
Definition types.hpp:18
Comparator for sorting ask levels (ascending price)
constexpr bool operator()(Price a, Price b) const noexcept
constexpr bool operator()(Price a, const PriceLevelL3 &b) const noexcept
constexpr bool operator()(const PriceLevelL3 &a, const PriceLevelL3 &b) const noexcept
constexpr bool operator()(const PriceLevelL3 &a, Price b) const noexcept
Comparator for sorting bid levels (descending price)
constexpr bool operator()(Price a, const PriceLevelL3 &b) const noexcept
constexpr bool operator()(const PriceLevelL3 &a, const PriceLevelL3 &b) const noexcept
constexpr bool operator()(Price a, Price b) const noexcept
constexpr bool operator()(const PriceLevelL3 &a, Price b) const noexcept
Order structure for Level 3 orderbook Uses intrusive list design for zero-allocation order queues at ...
Definition order.hpp:14
Price level for Level 3 orderbook (order-by-order) Maintains a queue of individual orders at this pri...
bool isEmpty() const noexcept
Check if this level is empty.
constexpr bool operator<(const PriceLevelL3 &other) const noexcept
void removeOrder(Order *order) noexcept
Remove order from the level.
Order * getBestOrder() noexcept
Get best order (first in queue)
constexpr bool operator!=(const PriceLevelL3 &other) const noexcept
std::size_t orderCount() const noexcept
Get number of orders at this level.
Quantity getTotalQuantity() const noexcept
Get total quantity at this level.
void insertOrder(Order *order) noexcept
Insert order maintaining priority order.
constexpr bool operator>(const PriceLevelL3 &other) const noexcept
constexpr bool operator==(const PriceLevelL3 &other) const noexcept
Comparison operators for sorting by price.
const Order * getBestOrder() const noexcept
void updateOrderQuantity(Quantity old_quantity, Quantity new_quantity) noexcept
Update order quantity (for modify operations)