diff --git a/src/lib_spark/spark/domain/Book.h b/src/lib_spark/spark/domain/Book.h index 960e72661..e999cc6b1 100644 --- a/src/lib_spark/spark/domain/Book.h +++ b/src/lib_spark/spark/domain/Book.h @@ -19,6 +19,13 @@ class BookT { [[nodiscard]] static constexpr size_t max_depth(); [[nodiscard]] constexpr std::size_t size() const noexcept; + /** + * @brief Gets the number of price levels with non-zero quantities (the sum of such levels on + * both sides of the market, bids and asks). + * + * @return constexpr std::size_t The number of price levels with non-zero quantities + */ + [[nodiscard]] std::size_t count_populated() const noexcept; [[nodiscard]] constexpr BS &bids() noexcept; [[nodiscard]] constexpr const BS &bids() const noexcept; @@ -34,6 +41,7 @@ class BookT { template void merge_with(OtherBook const &b); + void clear(); void clear_to_end(std::size_t level = 0); void clear_after_empty(); [[nodiscard]] bool is_sorted() const; @@ -98,6 +106,11 @@ constexpr std::size_t BookT::size() const noexcept { return _books.size(); } +template +std::size_t BookT::count_populated() const noexcept { + return _books[0].count_populated() + _books[1].count_populated(); +} + template constexpr BS &BookT::bids() noexcept { return _books[Side::Buy]; @@ -184,6 +197,11 @@ void BookT::remove_crosses(Side dominant_side) { dominant_side.other(), (*this)[dominant_side][0].price); } +template +void BookT::clear() { + Side::foreach ([&](Side s) { operator[](s).clear(); }); +} + template void BookT::clear_to_end(std::size_t level) { Side::foreach ([&](Side s) { diff --git a/src/lib_spark/spark/domain/BookSide.h b/src/lib_spark/spark/domain/BookSide.h index 68be365c7..bd6b331f9 100644 --- a/src/lib_spark/spark/domain/BookSide.h +++ b/src/lib_spark/spark/domain/BookSide.h @@ -120,6 +120,7 @@ class BookSideT { [[nodiscard]] Quantity intersecting_front_quantity( const OtherBookSide &other, std::size_t num_levels = max_depth()) const; + void clear(); void clear_to_end(std::uint8_t level = 0); void clear_after_empty(); @@ -592,6 +593,11 @@ Quantity BookSideT::intersecting_front_quantity( return ifq; } +template +void BookSideT::clear() { + clear_to_end(0); +} + template void BookSideT::clear_to_end(std::uint8_t level) { static_assert(SZ <= std::numeric_limits::max());