FastMM documentation
FastMM C++ API 0.14.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 Types

using Levels = StaticVector< Level, kMaxDepth+kOwnLevels >
 Raw access (worst..best order) for tests/tools.
 

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.
 
FASTMM_FORCE_INLINE bool apply_level (Side side, Price price, Qty qty, Qty &old) noexcept
 The same; old is the quantity the level had (zero when absent).
 
bool add_own (Side side, Price price, Qty qty, bool &inserted) noexcept
 
void remove_own (Side side, Price price, Qty qty, bool inserted) noexcept
 
void apply_snapshot (std::span< const Level > bids, std::span< const Level > asks, std::uint64_t seq, Timestamp ts) noexcept
 O(levels) for a snapshot sorted best-first or worst-first with no empty level (what every parser sends); any other input is applied level by level.
 
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 Levels & raw (Side side) const noexcept
 

Static Public Attributes

static constexpr std::size_t kDepth = kMaxDepth
 
static constexpr std::size_t kLinearScan = 16
 
static constexpr std::size_t kOwnLevels = 32
 Our own quantity shown in a book that is otherwise the market's (the engine's view of a simulated feed that shows our orders, OwnLevelsMsg): add_own() adds qty at price, a level of its own where there is none, beyond kMaxDepth if the side is full (a side has room for kOwnLevels more); remove_own() takes it out again, which leaves the book as it was when nothing else changed it in between.
 

Member Typedef Documentation

◆ Levels

template<std::size_t kMaxDepth = 256>
using fastmm::L2Book< kMaxDepth >::Levels = StaticVector<Level, kMaxDepth + kOwnLevels>

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

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() [1/2]

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.

◆ apply_level() [2/2]

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

The same; old is the quantity the level had (zero when absent).

< delete of an unknown level: no-op

< worse than everything we hold

Drop the worst level and insert in one shift: only the i - 1 levels worse than the new one move, as an insert into a side with room moves the ones better than it.

◆ add_own()

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

◆ remove_own()

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

◆ 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

O(levels) for a snapshot sorted best-first or worst-first with no empty level (what every parser sends); any other input is applied level by level.

◆ 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 Levels & fastmm::L2Book< kMaxDepth >::raw ( Side  side) const
inlinenoexcept

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

◆ kOwnLevels

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

Our own quantity shown in a book that is otherwise the market's (the engine's view of a simulated feed that shows our orders, OwnLevelsMsg): add_own() adds qty at price, a level of its own where there is none, beyond kMaxDepth if the side is full (a side has room for kOwnLevels more); remove_own() takes it out again, which leaves the book as it was when nothing else changed it in between.

add_own() returns false, adding nothing, when there is no room.