FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
quote_diag.hpp
Go to the documentation of this file.
1#pragma once
2// Why a side of an instrument is or is not quoting (ctx.note_quote, the status file's quote
3// table): what the strategy last asked for on the side against the
4// orders working there, the first thing the engine finds in the way, and the strategy's own
5// reason and budget for the side. The engine knows its own obstacles (quoting off, a pull, a kill,
6// the feed-lag gate, a reject backoff, a wait for an order token, a refusal); why a model chose not
7// to quote, or quoted less than its budget, only the strategy can say.
9
10#include <cstddef>
11#include <cstdint>
12#include <string_view>
13
14namespace fastmm {
15
16inline constexpr std::size_t kQuoteNoteLen = 24; // QuoteNote::reason, NUL-terminated
17inline constexpr std::size_t kMaxStrategyMetrics = 32;
18inline constexpr std::size_t kStrategyMetricNameLen = 24;
19inline constexpr std::size_t kQuoteDiagAccounts = 8; // a pool's accounts (EngineConfig::pools)
21// The first obstacle between what the strategy asked for on a side and orders working there. The
22// engine checks them in this order, except that a venue kill comes before the pull it causes.
23enum class QuoteBlock : std::uint8_t {
24 Quoting = 0, // the working orders cover what the strategy asked for
25 NotWanted = 1, // the strategy asks for nothing on this side (its note may say why)
26 QuotingOff = 2, // the session does not quote: pulled, killed, reconciling, parameters stale
27 Pulled = 3, // this instrument or its venue is pulled (fastmm-ctl pull --instrument/--venue)
28 VenueKilled = 4, // its venue's kill switch
29 FeedLag = 5, // the venue's feed-lag gate holds ([risk] max_feed_lag_ms)
30 Backoff = 6, // a venue refusal put the side in its reject backoff
31 Starved = 7, // waiting for an order token ([risk] orders_per_sec)
32 Refused = 8, // the last order on the side was refused (`reason`) within the last 2 s
33 Pending = 9, // orders on their way: sent, not yet working, or a requote waiting its turn
34};
35[[nodiscard]] constexpr std::string_view to_string(QuoteBlock b) noexcept {
36 switch (b) {
38 return "quoting";
40 return "not_wanted";
42 return "quoting_off";
44 return "pulled";
46 return "venue_killed";
48 return "feed_lag";
50 return "backoff";
52 return "starved";
54 return "refused";
56 return "pending";
57 }
58 return "?";
59}
60
61// What the strategy says about a side (ctx.note_quote): a short reason ("inventory_cap",
62// "model_off", "cooldown"; empty: none) and the budget it gave the side, in the settlement
63// currency (raw 1e-8; 0: none given).
64struct QuoteNote {
65 char reason[kQuoteNoteLen] = {};
66 std::int64_t budget_raw = 0;
67 std::int64_t set_ns = 0; // engine time of the note
68 [[nodiscard]] std::string_view reason_view() const noexcept {
69 std::size_t n = 0;
70 while (n < kQuoteNoteLen && reason[n] != '\0') ++n;
71 return {reason, n};
72 }
73};
74
75// One side of an instrument as the engine publishes it (EngineLiveStats::quotes).
76struct LiveQuoteSide {
77 std::int64_t desired_px_raw = 0; // level 0 of the strategy's last ladder (0: none)
78 std::int64_t desired_qty_raw = 0; // over every level
79 std::int64_t working_px_raw = 0; // best working quote price (0: none)
80 std::int64_t working_qty_raw = 0; // leaves of every open order on the side
81 // Leaves of the working quotes by pool account (index in the pool, 0 the primary).
83 std::int64_t block_since_ns = 0; // engine time `block` began
84 std::uint16_t working_orders = 0;
85 std::uint8_t desired_levels = 0;
87 RejectReason reason = RejectReason::None; // block Refused: the refusal; otherwise None
88 std::uint8_t pad_[3] = {};
90};
93 std::uint32_t instrument = 0;
94 std::uint8_t venue = 0;
95 std::uint8_t pad_[3] = {};
96 std::int64_t position_raw = 0;
97 std::int64_t avg_px_raw = 0;
98 std::int64_t realized_raw = 0;
99 std::int64_t unrealized_raw = 0;
100 std::int64_t mid_raw = 0; // 0: no two-sided book
101 LiveQuoteSide sides[2]; // by Side: Buy, Sell
104// A number the strategy publishes by name (ctx.metric): a budget split, a model state.
105struct LiveMetric {
106 char name[kStrategyMetricNameLen] = {};
107 double value = 0.0;
110} // namespace fastmm
All engine enumerations.
Definition strategy.hpp:16
QuoteBlock
The first obstacle between what the strategy asked for on a side and orders working there.
Definition quote_diag.hpp:25
@ Pulled
this instrument or its venue is pulled (fastmm-ctl pull --instrument/--venue)
@ Starved
waiting for an order token ([risk] orders_per_sec)
@ Pending
orders on their way: sent, not yet working, or a requote waiting its turn
@ Backoff
a venue refusal put the side in its reject backoff
@ QuotingOff
the session does not quote: pulled, killed, reconciling, parameters stale
@ FeedLag
the venue's feed-lag gate holds ([risk] max_feed_lag_ms)
@ Quoting
the working orders cover what the strategy asked for
@ VenueKilled
its venue's kill switch
@ NotWanted
the strategy asks for nothing on this side (its note may say why)
@ Refused
the last order on the side was refused (reason) within the last 2 s
constexpr std::size_t kMaxStrategyMetrics
Definition quote_diag.hpp:19
constexpr std::size_t kQuoteNoteLen
QuoteNote::reason, NUL-terminated.
Definition quote_diag.hpp:18
RejectReason
Ordered exactly like RiskEngine::check_new evaluates them (5.7), followed by OMS / transport / venue ...
Definition enums.hpp:123
@ FeedLag
[risk] max_feed_lag_ms: the venue's market data is late (core/venue_health.hpp) and the order could r...
constexpr std::size_t kQuoteDiagAccounts
a pool's accounts (EngineConfig::pools)
Definition quote_diag.hpp:21
constexpr std::string_view to_string(ParamType t) noexcept
Definition params.hpp:63
constexpr std::size_t kStrategyMetricNameLen
Definition quote_diag.hpp:20
A number the strategy publishes by name (ctx.metric): a budget split, a model state.
Definition quote_diag.hpp:107
double value
Definition quote_diag.hpp:109
char name[kStrategyMetricNameLen]
Definition quote_diag.hpp:108
Definition quote_diag.hpp:94
std::uint8_t pad_[3]
Definition quote_diag.hpp:97
std::int64_t unrealized_raw
Definition quote_diag.hpp:101
std::int64_t realized_raw
Definition quote_diag.hpp:100
std::int64_t avg_px_raw
Definition quote_diag.hpp:99
LiveQuoteSide sides[2]
by Side: Buy, Sell
Definition quote_diag.hpp:103
std::int64_t mid_raw
0: no two-sided book
Definition quote_diag.hpp:102
std::uint8_t venue
Definition quote_diag.hpp:96
std::uint32_t instrument
Definition quote_diag.hpp:95
std::int64_t position_raw
Definition quote_diag.hpp:98
One side of an instrument as the engine publishes it (EngineLiveStats::quotes).
Definition quote_diag.hpp:78
std::int64_t account_qty_raw[kQuoteDiagAccounts]
Leaves of the working quotes by pool account (index in the pool, 0 the primary).
Definition quote_diag.hpp:84
RejectReason reason
block Refused: the refusal; otherwise None
Definition quote_diag.hpp:89
std::uint8_t pad_[3]
Definition quote_diag.hpp:90
std::int64_t working_qty_raw
leaves of every open order on the side
Definition quote_diag.hpp:82
std::int64_t block_since_ns
engine time block began
Definition quote_diag.hpp:85
std::int64_t working_px_raw
best working quote price (0: none)
Definition quote_diag.hpp:81
std::uint8_t desired_levels
Definition quote_diag.hpp:87
QuoteNote note
Definition quote_diag.hpp:91
std::int64_t desired_qty_raw
over every level
Definition quote_diag.hpp:80
std::uint16_t working_orders
Definition quote_diag.hpp:86
QuoteBlock block
Definition quote_diag.hpp:88
std::int64_t desired_px_raw
level 0 of the strategy's last ladder (0: none)
Definition quote_diag.hpp:79
What the strategy says about a side (ctx.note_quote): a short reason ("inventory_cap",...
Definition quote_diag.hpp:66
std::string_view reason_view() const noexcept
Definition quote_diag.hpp:70
char reason[kQuoteNoteLen]
Definition quote_diag.hpp:67
std::int64_t budget_raw
Definition quote_diag.hpp:68
std::int64_t set_ns
engine time of the note
Definition quote_diag.hpp:69