FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
book_view.hpp
Go to the documentation of this file.
1#pragma once
2// BookView: the read interface every book implementation (L2Book, L3Book::to_l2 view, sim
3// book) exposes to strategies and risk. Level lives in messages.hpp because market-data
4// messages carry it.
9
10#include <concepts>
11#include <cstddef>
12#include <cstdint>
13
14namespace fastmm {
15
16// Fixed-size result of top<N>().
17template <std::size_t N>
18struct TopLevels {
19 Level levels[N];
20 std::uint32_t count = 0;
21 [[nodiscard]] const Level& operator[](std::size_t i) const noexcept { return levels[i]; }
22 [[nodiscard]] const Level* begin() const noexcept { return levels; }
23 [[nodiscard]] const Level* end() const noexcept { return levels + count; }
24};
26template <class B>
27concept BookView = requires(const B& b, Side s, std::size_t i, Qty q, Price p) {
28 { b.best_bid() } noexcept -> std::same_as<Level>;
29 { b.best_ask() } noexcept -> std::same_as<Level>;
30 { b.mid() } noexcept -> std::same_as<Price>;
31 { b.spread() } noexcept -> std::same_as<Price>;
32 { b.level(s, i) } noexcept -> std::same_as<Level>;
33 { b.depth(s) } noexcept -> std::same_as<std::size_t>;
34 { b.qty_at_or_better(s, p) } noexcept -> std::same_as<Qty>;
35 { b.price_for_qty(s, q) } noexcept -> std::same_as<Price>;
36 { b.is_valid() } noexcept -> std::same_as<bool>;
37 { b.seq() } noexcept -> std::same_as<std::uint64_t>;
38 { b.last_update() } noexcept -> std::same_as<Timestamp>;
39 { b.template top<4>(s) } noexcept -> std::same_as<TopLevels<4>>;
40};
41
42// true if `p` is at least as good as `q` from the point of view of side s.
43[[nodiscard]] constexpr bool at_or_better(Side s, Price p, Price q) noexcept {
44 return s == Side::Buy ? p >= q : p <= q;
46[[nodiscard]] constexpr bool better(Side s, Price p, Price q) noexcept {
47 return s == Side::Buy ? p > q : p < q;
49
50} // namespace fastmm
Definition book_view.hpp:29
All engine enumerations.
Fixed<Tag>: int64 fixed point with a global 1e-8 scale (ADR-0001).
Event bus message structs (5.5).
Definition strategy.hpp:16
Side
Definition enums.hpp:12
constexpr bool at_or_better(Side s, Price p, Price q) noexcept
true if p is at least as good as q from the point of view of side s.
Definition book_view.hpp:45
Fixed< struct PriceTag > Price
Definition fixed_point.hpp:332
constexpr bool better(Side s, Price p, Price q) noexcept
Definition book_view.hpp:48
One price level. Shared by book messages and the L2 book.
Definition messages.hpp:30
const Level * begin() const noexcept
Definition book_view.hpp:24
std::uint32_t count
Definition book_view.hpp:22
const Level * end() const noexcept
Definition book_view.hpp:25
Level levels[N]
Definition book_view.hpp:21
const Level & operator[](std::size_t i) const noexcept
Definition book_view.hpp:23
Time primitives.