23 using iterator =
typename std::vector<PriceLevelL2>::iterator;
39 levels_.reserve(initial_capacity);
48 [[nodiscard]] std::size_t
size() const noexcept {
49 return levels_.size();
53 [[nodiscard]]
bool empty() const noexcept {
54 return levels_.empty();
59 return levels_[index];
64 return levels_.at(index);
69 return levels_.empty() ? nullptr : &levels_.front();
76 auto it = std::lower_bound(levels_.begin(), levels_.end(), key, compare_);
77 if (it != levels_.end() && it->price == price) {
86 auto it = std::lower_bound(levels_.begin(), levels_.end(), key, compare_);
87 if (it != levels_.end() && it->price == price) {
95 auto it = find(price);
96 return (it != levels_.end()) ? &(*it) :
nullptr;
105 auto it = std::lower_bound(levels_.begin(), levels_.end(), key, compare_);
108 if (it != levels_.end() && it->price == price) {
110 it->quantity = quantity;
111 it->timestamp = timestamp;
116 it = levels_.insert(it,
PriceLevelL2{price, quantity, timestamp});
123 auto it = find(price);
124 if (it != levels_.end()) {
133 return levels_.erase(it);
143 levels_.reserve(capacity);
147 [[nodiscard]] std::size_t
capacity() const noexcept {
148 return levels_.capacity();
153 [[nodiscard]] std::vector<PriceLevelL2>
getLevels(std::size_t depth = 0)
const {
154 if (depth == 0 || depth >= levels_.size()) {
157 return std::vector<PriceLevelL2>(levels_.begin(), levels_.begin() + depth);
171 std::vector<PriceLevelL2> levels_;
Container for storing sorted price levels Uses a sorted vector for cache-friendly storage (optimal fo...
std::function< bool(const PriceLevelL2 &, const PriceLevelL2 &)> Comparator
const_iterator end() const noexcept
const_iterator begin() const noexcept
typename std::vector< PriceLevelL2 >::iterator iterator
LevelContainer(Side side, std::size_t initial_capacity=32)
Constructor with side and initial capacity.
iterator erase(iterator it) noexcept
Remove level by iterator.
iterator find(Price price) noexcept
Find level by price (binary search) Returns iterator to level with matching price,...
bool erase(Price price) noexcept
Remove level by price Returns true if level was found and removed.
Side side() const noexcept
Get Side.
std::size_t capacity() const noexcept
Get capacity.
const PriceLevelL2 * best() const noexcept
Get best level (first element)
iterator begin() noexcept
Iterators.
const PriceLevelL2 & operator[](std::size_t index) const noexcept
Get level at index (no bounds checking)
bool empty() const noexcept
Check if empty.
LevelContainer()
Default constructor (for array initialization on MSVC)
typename std::vector< PriceLevelL2 >::const_iterator const_iterator
std::vector< PriceLevelL2 > getLevels(std::size_t depth=0) const
Get all levels up to depth.
const PriceLevelL2 & at(std::size_t index) const
Get level at index with bounds checking.
void clear() noexcept
Clear all levels.
const PriceLevelL2 * getLevel(Price price) const noexcept
Get level by price (returns pointer or nullptr)
const_iterator find(Price price) const noexcept
Find level by price (binary search, const version)
std::pair< iterator, bool > insertOrUpdate(Price price, Quantity quantity, Timestamp timestamp)
Insert or update a level If price exists, updates quantity; otherwise inserts new level Returns itera...
std::size_t size() const noexcept
Get number of levels.
const_iterator cend() const noexcept
void reserve(std::size_t capacity)
Reserve capacity.
const_iterator cbegin() const noexcept
#define SLICK_DETAIL_NAMESPACE_BEGIN
#define SLICK_DETAIL_NAMESPACE_END
int64_t Quantity
Quantity type - volume or size.
int64_t Price
Price type - fixed-point representation Example: For 4 decimal places, price = actual_price * 10000 T...
Side
Order side - using enum for easy array indexing.
uint64_t Timestamp
Timestamp in nanoseconds since epoch.
Comparator for sorting ask levels (ascending price)
Comparator for sorting bid levels (descending price)
Price level for Level 2 orderbook (aggregated) Stores total quantity at a specific price point.