FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::L2Book< kMaxDepth > Class Template Reference

#include <fastmm/core/book/l2_book.hpp>

Public Member Functions

 L2Book () noexcept=default
 
void clear () noexcept
 
FASTMM_FORCE_INLINE bool apply_level (Side side, Price price, Qty qty) noexcept
 Sets/updates/deletes (qty == 0) one level.
 
void apply_snapshot (std::span< const Level > bids, std::span< const Level > asks, std::uint64_t seq, Timestamp ts) noexcept
 
void apply_delta (const BookDeltaMsg &d) noexcept
 Applies a BookDeltaMsg (or snapshot with kSnapshot).
 
void set_seq (std::uint64_t s) noexcept
 
void set_last_update (Timestamp t) noexcept
 
void mark_snapshot () noexcept
 
FASTMM_FORCE_INLINE Level best_bid () const noexcept
 
FASTMM_FORCE_INLINE Level best_ask () const noexcept
 
Price mid () const noexcept
 
Price spread () const noexcept
 
Level level (Side side, std::size_t i) const noexcept
 i == 0 is best. Level{} if out of range.
 
std::size_t depth (Side side) const noexcept
 
std::size_t depth () const noexcept
 
Qty qty_at_or_better (Side side, Price limit) const noexcept
 Total quantity on side at prices at-or-better than limit.
 
Price price_for_qty (Side side, Qty qty) const noexcept
 Price of the level at which cumulative quantity from the best reaches qty; Price{} if the side is too thin.
 
template<class F >
void for_each_level (Side side, F &&f) const noexcept
 Visits levels best-first. F(const Level&) may return bool (false stops) or void.
 
template<std::size_t N>
TopLevels< N > top (Side side) const noexcept
 
bool crossed () const noexcept
 
Duration crossed_for (Timestamp now) const noexcept
 How long the book has been crossed as of now (zero if not crossed).
 
bool truncated (Side side) const noexcept
 
bool truncated () const noexcept
 
bool has_snapshot () const noexcept
 
bool is_valid () const noexcept
 
std::uint64_t seq () const noexcept
 
Timestamp last_update () const noexcept
 
const StaticVector< Level, kMaxDepth > & raw (Side side) const noexcept
 Raw access (worst..best order) for tests/tools.
 

Static Public Attributes

static constexpr std::size_t kDepth = kMaxDepth
 
static constexpr std::size_t kLinearScan = 16
 

Constructor & Destructor Documentation

◆ L2Book()

template<std::size_t kMaxDepth = 256>
fastmm::L2Book< kMaxDepth >::L2Book ( )
defaultnoexcept

Member Function Documentation

◆ clear()

template<std::size_t kMaxDepth = 256>
void fastmm::L2Book< kMaxDepth >::clear ( )
inlinenoexcept

◆ apply_level()

template<std::size_t kMaxDepth = 256>
FASTMM_FORCE_INLINE bool fastmm::L2Book< kMaxDepth >::apply_level ( Side  side,
Price  price,
Qty  qty 
)
inlinenoexcept

Sets/updates/deletes (qty == 0) one level.

Returns false if the level was dropped because the side is full and the price is worse than everything stored.

Position such that v[i].price is the first level at-or-better than price when scanning from the worst (front) - i.e. lower_bound in "goodness" order.

Linear scan from the best (back) over the top kLinearScan levels.

< insert after v[i-1]

Bisect the remainder [0, stop): find first index whose price is at-or-better.

< delete of an unknown level: no-op

< worse than everything we hold

< drop the worst level to make room

◆ apply_snapshot()

template<std::size_t kMaxDepth = 256>
void fastmm::L2Book< kMaxDepth >::apply_snapshot ( std::span< const Level >  bids,
std::span< const Level >  asks,
std::uint64_t  seq,
Timestamp  ts 
)
inlinenoexcept

◆ apply_delta()

template<std::size_t kMaxDepth = 256>
void fastmm::L2Book< kMaxDepth >::apply_delta ( const BookDeltaMsg &  d)
inlinenoexcept

Applies a BookDeltaMsg (or snapshot with kSnapshot).

Uses last_update_id as seq and exch_ts (falling back to recv_ts) as the update time.

◆ set_seq()

template<std::size_t kMaxDepth = 256>
void fastmm::L2Book< kMaxDepth >::set_seq ( std::uint64_t  s)
inlinenoexcept

◆ set_last_update()

template<std::size_t kMaxDepth = 256>
void fastmm::L2Book< kMaxDepth >::set_last_update ( Timestamp  t)
inlinenoexcept

◆ mark_snapshot()

template<std::size_t kMaxDepth = 256>
void fastmm::L2Book< kMaxDepth >::mark_snapshot ( )
inlinenoexcept

◆ best_bid()

template<std::size_t kMaxDepth = 256>
FASTMM_FORCE_INLINE Level fastmm::L2Book< kMaxDepth >::best_bid ( ) const
inlinenoexcept

◆ best_ask()

template<std::size_t kMaxDepth = 256>
FASTMM_FORCE_INLINE Level fastmm::L2Book< kMaxDepth >::best_ask ( ) const
inlinenoexcept

◆ mid()

template<std::size_t kMaxDepth = 256>
Price fastmm::L2Book< kMaxDepth >::mid ( ) const
inlinenoexcept

◆ spread()

template<std::size_t kMaxDepth = 256>
Price fastmm::L2Book< kMaxDepth >::spread ( ) const
inlinenoexcept

◆ level()

template<std::size_t kMaxDepth = 256>
Level fastmm::L2Book< kMaxDepth >::level ( Side  side,
std::size_t  i 
) const
inlinenoexcept

i == 0 is best. Level{} if out of range.

◆ depth() [1/2]

template<std::size_t kMaxDepth = 256>
std::size_t fastmm::L2Book< kMaxDepth >::depth ( Side  side) const
inlinenoexcept

◆ depth() [2/2]

template<std::size_t kMaxDepth = 256>
std::size_t fastmm::L2Book< kMaxDepth >::depth ( ) const
inlinenoexcept

◆ qty_at_or_better()

template<std::size_t kMaxDepth = 256>
Qty fastmm::L2Book< kMaxDepth >::qty_at_or_better ( Side  side,
Price  limit 
) const
inlinenoexcept

Total quantity on side at prices at-or-better than limit.

◆ price_for_qty()

template<std::size_t kMaxDepth = 256>
Price fastmm::L2Book< kMaxDepth >::price_for_qty ( Side  side,
Qty  qty 
) const
inlinenoexcept

Price of the level at which cumulative quantity from the best reaches qty; Price{} if the side is too thin.

◆ for_each_level()

template<std::size_t kMaxDepth = 256>
template<class F >
void fastmm::L2Book< kMaxDepth >::for_each_level ( Side  side,
F &&  f 
) const
inlinenoexcept

Visits levels best-first. F(const Level&) may return bool (false stops) or void.

◆ top()

template<std::size_t kMaxDepth = 256>
template<std::size_t N>
TopLevels< N > fastmm::L2Book< kMaxDepth >::top ( Side  side) const
inlinenoexcept

◆ crossed()

template<std::size_t kMaxDepth = 256>
bool fastmm::L2Book< kMaxDepth >::crossed ( ) const
inlinenoexcept

◆ crossed_for()

template<std::size_t kMaxDepth = 256>
Duration fastmm::L2Book< kMaxDepth >::crossed_for ( Timestamp  now) const
inlinenoexcept

How long the book has been crossed as of now (zero if not crossed).

◆ truncated() [1/2]

template<std::size_t kMaxDepth = 256>
bool fastmm::L2Book< kMaxDepth >::truncated ( Side  side) const
inlinenoexcept

◆ truncated() [2/2]

template<std::size_t kMaxDepth = 256>
bool fastmm::L2Book< kMaxDepth >::truncated ( ) const
inlinenoexcept

◆ has_snapshot()

template<std::size_t kMaxDepth = 256>
bool fastmm::L2Book< kMaxDepth >::has_snapshot ( ) const
inlinenoexcept

◆ is_valid()

template<std::size_t kMaxDepth = 256>
bool fastmm::L2Book< kMaxDepth >::is_valid ( ) const
inlinenoexcept

◆ seq()

template<std::size_t kMaxDepth = 256>
std::uint64_t fastmm::L2Book< kMaxDepth >::seq ( ) const
inlinenoexcept

◆ last_update()

template<std::size_t kMaxDepth = 256>
Timestamp fastmm::L2Book< kMaxDepth >::last_update ( ) const
inlinenoexcept

◆ raw()

template<std::size_t kMaxDepth = 256>
const StaticVector< Level, kMaxDepth > & fastmm::L2Book< kMaxDepth >::raw ( Side  side) const
inlinenoexcept

Raw access (worst..best order) for tests/tools.

Member Data Documentation

◆ kDepth

template<std::size_t kMaxDepth = 256>
constexpr std::size_t fastmm::L2Book< kMaxDepth >::kDepth = kMaxDepth
staticconstexpr

◆ kLinearScan

template<std::size_t kMaxDepth = 256>
constexpr std::size_t fastmm::L2Book< kMaxDepth >::kLinearScan = 16
staticconstexpr