FastMM documentation
FastMM C++ API 0.14.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, the fill-cluster guard, a hazard group, a window, a reject backoff, a wait for
7// an order token, a refusal); why a model chose not to quote, or quoted less than its budget, only
8// the strategy can say.
10
11#include <cstddef>
12#include <cstdint>
13#include <string_view>
14
15namespace fastmm {
16
17inline constexpr std::size_t kQuoteNoteLen = 24; // QuoteNote::reason, NUL-terminated
18inline constexpr std::size_t kMaxStrategyMetrics = 32;
19inline constexpr std::size_t kStrategyMetricNameLen = 24;
20inline constexpr std::size_t kQuoteDiagAccounts = 8; // a pool's accounts (EngineConfig::pools)
22// The first obstacle between what the strategy asked for on a side and orders working there. The
23// engine checks them in this order, except that a venue kill comes before the pull it causes.
24enum class QuoteBlock : std::uint8_t {
25 Quoting = 0, // the working orders cover what the strategy asked for
26 NotWanted = 1, // the strategy asks for nothing on this side (its note may say why)
27 QuotingOff = 2, // the session does not quote: pulled, killed, reconciling, parameters stale
28 Pulled = 3, // this instrument or its venue is pulled (fastmm-ctl pull --instrument/--venue)
29 VenueKilled = 4, // its venue's kill switch
30 FeedLag = 5, // the venue's feed-lag gate holds ([risk] max_feed_lag_ms)
31 Backoff = 6, // a venue refusal put the side in its reject backoff
32 Starved = 7, // waiting for an order token ([risk] orders_per_sec)
33 Refused = 8, // the last order on the side was refused (`reason`) within the last 2 s
34 Pending = 9, // orders on their way: sent, not yet working, or a requote waiting its turn
35 FillCluster = 10, // the fill-cluster guard holds the side ([risk] fill_cluster_names)
36 Hazard = 11, // a hazard group holds the side ([[risk.hazard]])
37 Window = 12, // an open [[windows]] window with action = "pull" covers the instrument
38 NotTrading = 13, // the venue does not trade the instrument now (Instrument::status)
39};
40[[nodiscard]] constexpr std::string_view to_string(QuoteBlock b) noexcept {
41 switch (b) {
43 return "quoting";
45 return "not_wanted";
47 return "quoting_off";
49 return "pulled";
51 return "venue_killed";
53 return "feed_lag";
55 return "backoff";
57 return "starved";
59 return "refused";
61 return "pending";
63 return "fill_cluster";
65 return "hazard";
67 return "window";
69 return "not_trading";
70 }
71 return "?";
72}
73
74// What the strategy says about a side (ctx.note_quote): a short reason ("inventory_cap",
75// "model_off", "cooldown"; empty: none) and the budget it gave the side, in the settlement
76// currency (raw 1e-8; 0: none given).
77struct QuoteNote {
78 char reason[kQuoteNoteLen] = {};
79 std::int64_t budget_raw = 0;
80 std::int64_t set_ns = 0; // engine time of the note
81 [[nodiscard]] std::string_view reason_view() const noexcept {
82 std::size_t n = 0;
83 while (n < kQuoteNoteLen && reason[n] != '\0') ++n;
84 return {reason, n};
85 }
86};
87
88// One side of an instrument as the engine publishes it (EngineLiveStats::quotes).
89struct LiveQuoteSide {
90 std::int64_t desired_px_raw = 0; // level 0 of the strategy's last ladder (0: none)
91 std::int64_t desired_qty_raw = 0; // over every level
92 std::int64_t working_px_raw = 0; // best working quote price (0: none)
93 std::int64_t working_qty_raw = 0; // leaves of every open order on the side
94 // Leaves of the working quotes by pool account (index in the pool, 0 the primary).
96 std::int64_t block_since_ns = 0; // engine time `block` began
97 std::uint16_t working_orders = 0;
98 std::uint8_t desired_levels = 0;
100 RejectReason reason = RejectReason::None; // block Refused: the refusal; otherwise None
101 std::uint8_t pad_[3] = {};
105struct LiveQuoteInstrument {
106 std::uint32_t instrument = 0;
107 std::uint8_t venue = 0;
108 std::uint8_t reduce_only = 0; // reduce-only mode holds the instrument
109 std::uint8_t arm = 0; // the [ab] arm it is in: 0 none, k + 1 arm k
110 std::uint8_t own_params = 0; // parameters it holds values of its own for
111 std::uint8_t home = 0xFF; // its home's venue id in its account pool (0xFF: none)
112 std::uint8_t pieces = 0; // accounts other than the home that hold it
113 std::uint8_t pad_[6] = {};
114 std::int64_t position_raw = 0;
115 std::int64_t avg_px_raw = 0;
116 std::int64_t realized_raw = 0;
117 std::int64_t unrealized_raw = 0;
118 std::int64_t mid_raw = 0; // 0: no two-sided book
119 LiveQuoteSide sides[2]; // by Side: Buy, Sell
122// A number the strategy publishes by name (ctx.metric): a budget split, a model state.
123struct LiveMetric {
124 char name[kStrategyMetricNameLen] = {};
125 double value = 0.0;
128} // namespace fastmm
All engine enumerations.
Definition strategy.hpp:23
QuoteBlock
The first obstacle between what the strategy asked for on a side and orders working there.
Definition quote_diag.hpp:26
@ 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
@ NotTrading
the venue does not trade the instrument now (Instrument::status)
@ Backoff
a venue refusal put the side in its reject backoff
@ QuotingOff
the session does not quote: pulled, killed, reconciling, parameters stale
@ FillCluster
the fill-cluster guard holds the side ([risk] fill_cluster_names)
@ FeedLag
the venue's feed-lag gate holds ([risk] max_feed_lag_ms)
@ Quoting
the working orders cover what the strategy asked for
@ Window
an open [[windows]] window with action = "pull" covers the instrument
@ VenueKilled
its venue's kill switch
@ NotWanted
the strategy asks for nothing on this side (its note may say why)
@ Hazard
a hazard group holds the side ([[risk.hazard]])
@ Refused
the last order on the side was refused (reason) within the last 2 s
constexpr std::size_t kMaxStrategyMetrics
Definition quote_diag.hpp:20
constexpr std::size_t kQuoteNoteLen
QuoteNote::reason, NUL-terminated.
Definition quote_diag.hpp:19
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:22
constexpr std::string_view to_string(ParamType t) noexcept
Definition params.hpp:63
constexpr std::size_t kStrategyMetricNameLen
Definition quote_diag.hpp:21
A number the strategy publishes by name (ctx.metric): a budget split, a model state.
Definition quote_diag.hpp:125
double value
Definition quote_diag.hpp:127
char name[kStrategyMetricNameLen]
Definition quote_diag.hpp:126
Definition quote_diag.hpp:107
std::uint8_t arm
the [ab] arm it is in: 0 none, k + 1 arm k
Definition quote_diag.hpp:111
std::int64_t unrealized_raw
Definition quote_diag.hpp:119
std::uint8_t pad_[6]
Definition quote_diag.hpp:115
std::int64_t realized_raw
Definition quote_diag.hpp:118
std::int64_t avg_px_raw
Definition quote_diag.hpp:117
LiveQuoteSide sides[2]
by Side: Buy, Sell
Definition quote_diag.hpp:121
std::int64_t mid_raw
0: no two-sided book
Definition quote_diag.hpp:120
std::uint8_t pieces
accounts other than the home that hold it
Definition quote_diag.hpp:114
std::uint8_t venue
Definition quote_diag.hpp:109
std::uint8_t home
its home's venue id in its account pool (0xFF: none)
Definition quote_diag.hpp:113
std::uint8_t own_params
parameters it holds values of its own for
Definition quote_diag.hpp:112
std::uint32_t instrument
Definition quote_diag.hpp:108
std::int64_t position_raw
Definition quote_diag.hpp:116
std::uint8_t reduce_only
reduce-only mode holds the instrument
Definition quote_diag.hpp:110
One side of an instrument as the engine publishes it (EngineLiveStats::quotes).
Definition quote_diag.hpp:91
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:97
RejectReason reason
block Refused: the refusal; otherwise None
Definition quote_diag.hpp:102
std::uint8_t pad_[3]
Definition quote_diag.hpp:103
std::int64_t working_qty_raw
leaves of every open order on the side
Definition quote_diag.hpp:95
std::int64_t block_since_ns
engine time block began
Definition quote_diag.hpp:98
std::int64_t working_px_raw
best working quote price (0: none)
Definition quote_diag.hpp:94
std::uint8_t desired_levels
Definition quote_diag.hpp:100
QuoteNote note
Definition quote_diag.hpp:104
std::int64_t desired_qty_raw
over every level
Definition quote_diag.hpp:93
std::uint16_t working_orders
Definition quote_diag.hpp:99
QuoteBlock block
Definition quote_diag.hpp:101
std::int64_t desired_px_raw
level 0 of the strategy's last ladder (0: none)
Definition quote_diag.hpp:92
What the strategy says about a side (ctx.note_quote): a short reason ("inventory_cap",...
Definition quote_diag.hpp:79
std::string_view reason_view() const noexcept
Definition quote_diag.hpp:83
char reason[kQuoteNoteLen]
Definition quote_diag.hpp:80
std::int64_t budget_raw
Definition quote_diag.hpp:81
std::int64_t set_ns
engine time of the note
Definition quote_diag.hpp:82