Slick OrderBook 1.1.0
High-Performance C++23 OrderBook Library
Loading...
Searching...
No Matches
price_level_l2.hpp
Go to the documentation of this file.
1// Copyright 2026 Slick Quant
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
8
10
14 Price price; // Price level
15 Quantity quantity; // Total quantity at this price
16 Timestamp timestamp; // Last update timestamp
17
18 constexpr PriceLevelL2() noexcept
19 : price(0), quantity(0), timestamp(0) {}
20
21 constexpr PriceLevelL2(Price p, Quantity q, Timestamp ts) noexcept
22 : price(p), quantity(q), timestamp(ts) {}
23
25 [[nodiscard]] constexpr bool isEmpty() const noexcept {
26 return quantity == 0;
27 }
28
30 [[nodiscard]] constexpr bool operator==(const PriceLevelL2& other) const noexcept {
31 return price == other.price;
32 }
33
34 [[nodiscard]] constexpr bool operator!=(const PriceLevelL2& other) const noexcept {
35 return price != other.price;
36 }
37
38 [[nodiscard]] constexpr bool operator<(const PriceLevelL2& other) const noexcept {
39 return price < other.price;
40 }
41
42 [[nodiscard]] constexpr bool operator>(const PriceLevelL2& other) const noexcept {
43 return price > other.price;
44 }
45
46 [[nodiscard]] constexpr bool operator<=(const PriceLevelL2& other) const noexcept {
47 return price <= other.price;
48 }
49
50 [[nodiscard]] constexpr bool operator>=(const PriceLevelL2& other) const noexcept {
51 return price >= other.price;
52 }
53};
54
57 [[nodiscard]] constexpr bool operator()(const PriceLevelL2& a, const PriceLevelL2& b) const noexcept {
58 return a.price > b.price; // Descending: highest bid first
59 }
60
61 [[nodiscard]] constexpr bool operator()(Price a, const PriceLevelL2& b) const noexcept {
62 return a > b.price;
63 }
64
65 [[nodiscard]] constexpr bool operator()(const PriceLevelL2& a, Price b) const noexcept {
66 return a.price > b;
67 }
68
69 [[nodiscard]] constexpr bool operator()(Price a, Price b) const noexcept {
70 return a > b;
71 }
72};
73
76 [[nodiscard]] constexpr bool operator()(const PriceLevelL2& a, const PriceLevelL2& b) const noexcept {
77 return a.price < b.price; // Ascending: lowest ask first
78 }
79
80 [[nodiscard]] constexpr bool operator()(Price a, const PriceLevelL2& b) const noexcept {
81 return a < b.price;
82 }
83
84 [[nodiscard]] constexpr bool operator()(const PriceLevelL2& a, Price b) const noexcept {
85 return a.price < b;
86 }
87
88 [[nodiscard]] constexpr bool operator()(Price a, Price b) const noexcept {
89 return a < b;
90 }
91};
92
#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
uint64_t Timestamp
Timestamp in nanoseconds since epoch.
Definition types.hpp:30
Comparator for sorting ask levels (ascending price)
constexpr bool operator()(Price a, const PriceLevelL2 &b) const noexcept
constexpr bool operator()(Price a, Price b) const noexcept
constexpr bool operator()(const PriceLevelL2 &a, const PriceLevelL2 &b) const noexcept
constexpr bool operator()(const PriceLevelL2 &a, Price b) const noexcept
Comparator for sorting bid levels (descending price)
constexpr bool operator()(const PriceLevelL2 &a, Price b) const noexcept
constexpr bool operator()(Price a, Price b) const noexcept
constexpr bool operator()(Price a, const PriceLevelL2 &b) const noexcept
constexpr bool operator()(const PriceLevelL2 &a, const PriceLevelL2 &b) const noexcept
Price level for Level 2 orderbook (aggregated) Stores total quantity at a specific price point.
constexpr bool isEmpty() const noexcept
Check if this level is empty.
constexpr bool operator==(const PriceLevelL2 &other) const noexcept
Comparison operators for sorting.
constexpr bool operator<=(const PriceLevelL2 &other) const noexcept
constexpr PriceLevelL2(Price p, Quantity q, Timestamp ts) noexcept
constexpr bool operator<(const PriceLevelL2 &other) const noexcept
constexpr bool operator>(const PriceLevelL2 &other) const noexcept
constexpr bool operator!=(const PriceLevelL2 &other) const noexcept
constexpr bool operator>=(const PriceLevelL2 &other) const noexcept