FastMM documentation
FastMM C++ API 0.14.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
engine_config.hpp
Go to the documentation of this file.
1#pragma once
2// EngineConfig: the per-session settings an Engine is constructed with. Separate from engine.hpp so
3// the strategy registry and registration files do not parse the Engine template.
4#include "fastmm/core/account_pool.hpp"
5#include "fastmm/core/balance_book.hpp"
8#include "fastmm/core/fill_cluster.hpp"
9#include "fastmm/core/fx.hpp"
10#include "fastmm/core/hazard.hpp"
11#include "fastmm/core/perp_book.hpp"
12#include "fastmm/core/pool_homes.hpp"
14#include "fastmm/core/risk.hpp"
15#include "fastmm/core/thread_utils.hpp"
16#include "fastmm/core/time.hpp"
17#include "fastmm/core/underlying.hpp"
18#include "fastmm/core/windows.hpp"
19
20#include <cstdint>
21#include <string>
22#include <string_view>
23#include <vector>
24
25namespace fastmm {
26
27// [engine] base_flows: what the engine does with a change of a spot instrument's base asset that
28// neither its fills nor its transfers made (Engine::flow_tick).
29enum class BaseFlows : std::uint8_t {
30 Off = 0, // not looked for
31 Report = 1, // logged and journaled; the position stays
32 Adjust = 2, // ... and the position takes it, valued at the mid
33};
34// The value of [engine] base_flows ("off", "report", "adjust"; anything else is off).
35[[nodiscard]] constexpr BaseFlows base_flows_of(std::string_view s) noexcept {
36 return s == "adjust" ? BaseFlows::Adjust : s == "report" ? BaseFlows::Report : BaseFlows::Off;
38
39struct EngineConfig {
40 std::uint64_t session_id = 0;
41 std::uint64_t rng_seed = 1;
42 std::uint16_t session_epoch = 1;
43 std::uint32_t max_events_per_step = 64;
46 // The monitors' snapshots (live_stats(), the latency percentiles) are published every
47 // latency_publish_interval and on every change an operator sees. A backtest, which nobody
48 // watches, turns them off: what it records and computes is the same.
49 bool publish_live = true;
50 // Risk rejects are logged at WARN: the first of each reason, then at most one line per reason per
51 // interval with the number suppressed in between (0 logs every reject).
53 // [strategy] max_param_age_ms: quoting is disabled before the first ParamUpdate and while none
54 // was applied for this long (zero: off).
56 // [strategy] state_file / state_interval_s (strategies/hooks.hpp KeepsState): the engine takes
57 // the strategy's state() every state_interval and at the end for whoever runs it to write to
58 // state_file (Engine::take_strategy_state; empty: never), and hands initial_state to restore()
59 // once, after on_start (empty: nothing to restore). The loader reads the file, not the engine.
60 std::string state_file;
62 std::string initial_state;
63 // The state_version initial_state was written with (the state file's head, a checkpoint's
64 // record): a backtest and a live session refuse bytes of another version before they start.
65 std::uint32_t initial_state_version = 0;
66 // [engine] checkpoint_s: with a journal, a checkpoint is written to it this often
67 // (StrategyStateMsg Kind::Snapshot: the strategy's state() when it keeps state, the positions and
68 // the open orders; zero: never). The bytes handed to restore() are written once at the start
69 // whenever there are some.
71 // [engine] markout_ms: after each fill the record stream gets the instrument's mid at the fill
72 // and at each of these horizons (MarkoutRecord), at most kMaxMarkoutHorizons; empty: none.
73 std::vector<std::int64_t> markout_ms;
74 // [engine] ack_timeout_ms: an order still waiting for its ack this long is force-cancelled, so a
75 // lost request cannot hold a pool slot, a max_open_orders slot and max_position exposure for
76 // good (zero: off).
78 // Operator flatten (ControlCommand::Flatten, the control socket's `flatten`): how often the
79 // engine looks at the remaining position and sends the next reduce-only slice, how long it
80 // keeps trying (zero: until it is flat or the operator stops it) and the slippage allowance a
81 // `flatten` without --max-slippage-bps uses.
84 std::int64_t flatten_slippage_bps = 25;
85 // [engine] cancel_unknown = "own": an open order a reconciliation (or an ack) reports that the
86 // OMS does not know is cancelled only when its client order id is FastMM's with an epoch from
87 // 1 to session_epoch; any other is left alone. False ("all"): every one is cancelled.
88 bool cancel_unknown_own = false;
89 // [engine] base_flows, base_flows_settle_s, base_flows_from: for every base asset of the spot
90 // instruments (one that is no instrument's quote), the accounts' total of it less the position
91 // of its instruments is measured once a second; a change that holds for base_flows_settle is a
92 // flow. Measured from the session's first settled value, or from zero (from_zero: the position
93 // is to equal the accounts' balance, an offset at the start included).
97 // [engine] queue_conservatism (a backtest: [backtest] queue_conservatism), in bps of 1: how much
98 // of a level's shrink ahead of our order the queue estimate (StrategyContext::queue_ahead)
99 // credits to cancels ahead of it. 10000: none.
100 std::int64_t queue_conservatism_bps = 10'000;
101 // Net PnL carried over from earlier sessions ([risk] max_loss is a budget for the deployment,
102 // not per process); fastmm-live reads it from the durable kill state (core/session_state.hpp).
104 bool quoting_enabled = true;
105 // [risk] reduce_only: the session starts in reduce-only mode for every instrument
106 // (ControlCommand::ReduceOnly turns it off).
107 bool reduce_only = false;
108 // [venues.<x>] reduce_only: ... for the instruments of these venues, bit per venue id.
109 std::uint32_t reduce_only_venues = 0;
110 // Bit v: venue v's positions are not current until its first reconciliation ends. A live
111 // session sets it for the venues that replay executions at connect: until then the position is
112 // the store's plus whatever the replay has booked so far, and an order sized, hedged or
113 // risk-checked on it could double a hedge or pass a limit. No order is sent and quoting stays
114 // off until every such venue has reconciled (journal header await_reconcile, so a replay does
115 // the same).
116 std::uint32_t await_reconcile = 0;
117 // The venues' names ([venues.<name>]), indexed by venue id: log lines name an instrument
118 // `venue:symbol` (Engine::venue_name; "venue <id>" for an id without one).
119 std::vector<std::string> venue_names;
120 int cpu = -1;
121 SpinMode spin_mode = SpinMode::Busy;
123 // [risk] fill_cluster_names, fill_cluster_window_ms, fill_cluster_hold_ms: quote fills on one
124 // side over that many instruments within the window hold the side everywhere for the hold
125 // (core/fill_cluster.hpp; names 0: off).
126 FillClusterConfig fill_cluster;
127 // [[risk.hazard]]: groups of instruments with a hazard score per side; evidence that takes it to
128 // the group's threshold pulls that side's quotes on the members for the hold (core/hazard.hpp;
129 // none: off).
130 HazardConfig hazard;
131 // [[windows]]: recurring windows that pull a scope's quotes or hold it reduce-only while open,
132 // on the engine's clock (core/windows.hpp; none: off).
133 WindowsConfig windows;
135 // [accounting]: the settlement currencies and their FX sources (inactive: nothing converted).
136 FxPlan fx;
137 // Maker/taker rates per instrument (fee_table, config/config.hpp), what StrategyContext::fees
138 // reports. The simulated venue charges fills with the same table; a live venue reports its own.
140 // [risk.underlying]: the underlyings with a net position limit and their instruments (inactive:
141 // none).
142 UnderlyingPlan underlying;
143 // [risk] check_balance and the initial margin rates ([[instruments]] initial_margin) the balance
144 // check and the estimate use (core/balance_book.hpp).
145 BalanceConfig balance;
146 // [accounting] mark, stale_mark_ms, stale_funding_ms: what a derivative's position is valued at
147 // and when the venue's mark, index and funding are stale (core/perp_book.hpp).
148 PerpConfig perp;
149 // [venues.<x>] pool_of: the accounts behind each venue (core/account_pool.hpp). A new order on
150 // an instrument whose venue has members goes to one of them (NewOrderRequest::account, else by
151 // balance and remaining order window), and the order keeps it.
152 PoolPlan pools;
153 // [venues.<primary>.pool]: each pool's placement, its planner's settings and the pinned homes
154 // (core/pool_homes.hpp). A pool without the table routes by balance and keeps no homes.
155 PoolHomesPlan homes;
156 // [capacity]: the price of an order slot (core/capacity_price.hpp); mode off: none.
158};
160} // namespace fastmm
The capacity price ([capacity]): every action that uses an order slot is a purchase.
Definition fees.hpp:54
Fee rates per instrument, in centi-basis-points (integer) of the fill notional.
Definition strategy.hpp:23
constexpr Duration milliseconds(std::int64_t v) noexcept
Definition time.hpp:38
constexpr BaseFlows base_flows_of(std::string_view s) noexcept
The value of [engine] base_flows ("off", "report", "adjust"; anything else is off).
Definition engine_config.hpp:37
@ Off
none was asked for in this session
BaseFlows
[engine] base_flows: what the engine does with a change of a spot instrument's base asset that neithe...
Definition engine_config.hpp:31
@ Report
logged and journaled; the position stays
@ Adjust
... and the position takes it, valued at the mid
@ Off
not looked for
constexpr Duration seconds(std::int64_t v) noexcept
Definition time.hpp:41
QuoteManager (5.6): diffs the strategy's DesiredQuotes against the orders resting at the venue and em...
Definition capacity_price.hpp:77
Definition time.hpp:22
FillClusterConfig fill_cluster
[risk] fill_cluster_names, fill_cluster_window_ms, fill_cluster_hold_ms: quote fills on one side over...
Definition engine_config.hpp:128
std::uint16_t session_epoch
Definition engine_config.hpp:44
Duration reject_log_interval
Risk rejects are logged at WARN: the first of each reason, then at most one line per reason per inter...
Definition engine_config.hpp:54
std::vector< std::int64_t > markout_ms
[engine] markout_ms: after each fill the record stream gets the instrument's mid at the fill and at e...
Definition engine_config.hpp:75
std::vector< std::string > venue_names
The venues' names ([venues.
Definition engine_config.hpp:121
FeeTable fees
Maker/taker rates per instrument (fee_table, config/config.hpp), what StrategyContext::fees reports.
Definition engine_config.hpp:141
WindowsConfig windows
[[windows]]: recurring windows that pull a scope's quotes or hold it reduce-only while open,...
Definition engine_config.hpp:135
std::uint64_t rng_seed
Definition engine_config.hpp:43
Duration latency_publish_interval
Definition engine_config.hpp:47
Duration crossed_grace
Definition engine_config.hpp:46
UnderlyingPlan underlying
[risk.underlying]: the underlyings with a net position limit and their instruments (inactive: none).
Definition engine_config.hpp:144
PoolPlan pools
[venues.
Definition engine_config.hpp:154
RiskLimits risk
Definition engine_config.hpp:124
SpinMode spin_mode
Definition engine_config.hpp:123
std::uint64_t session_id
Definition engine_config.hpp:42
std::int64_t queue_conservatism_bps
[engine] queue_conservatism (a backtest: [backtest] queue_conservatism), in bps of 1: how much of a l...
Definition engine_config.hpp:102
bool publish_live
The monitors' snapshots (live_stats(), the latency percentiles) are published every latency_publish_i...
Definition engine_config.hpp:51
Duration ack_timeout
[engine] ack_timeout_ms: an order still waiting for its ack this long is force-cancelled,...
Definition engine_config.hpp:79
BalanceConfig balance
[risk] check_balance and the initial margin rates ([[instruments]] initial_margin) the balance check ...
Definition engine_config.hpp:147
std::uint32_t initial_state_version
The state_version initial_state was written with (the state file's head, a checkpoint's record): a ba...
Definition engine_config.hpp:67
PerpConfig perp
[accounting] mark, stale_mark_ms, stale_funding_ms: what a derivative's position is valued at and whe...
Definition engine_config.hpp:150
std::string state_file
[strategy] state_file / state_interval_s (strategies/hooks.hpp KeepsState): the engine takes the stra...
Definition engine_config.hpp:62
bool quoting_enabled
Definition engine_config.hpp:106
std::string initial_state
Definition engine_config.hpp:64
QuoteParams quotes
Definition engine_config.hpp:136
std::uint32_t max_events_per_step
Definition engine_config.hpp:45
HazardConfig hazard
[[risk.hazard]]: groups of instruments with a hazard score per side; evidence that takes it to the gr...
Definition engine_config.hpp:132
Duration state_interval
Definition engine_config.hpp:63
Notional pnl_carry
Net PnL carried over from earlier sessions ([risk] max_loss is a budget for the deployment,...
Definition engine_config.hpp:105
bool base_flows_from_zero
Definition engine_config.hpp:98
Duration base_flows_settle
Definition engine_config.hpp:97
Duration max_param_age
[strategy] max_param_age_ms: quoting is disabled before the first ParamUpdate and while none was appl...
Definition engine_config.hpp:57
BaseFlows base_flows
[engine] base_flows, base_flows_settle_s, base_flows_from: for every base asset of the spot instrumen...
Definition engine_config.hpp:96
std::uint32_t await_reconcile
Bit v: venue v's positions are not current until its first reconciliation ends.
Definition engine_config.hpp:118
bool reduce_only
[risk] reduce_only: the session starts in reduce-only mode for every instrument (ControlCommand::Redu...
Definition engine_config.hpp:109
FxPlan fx
[accounting]: the settlement currencies and their FX sources (inactive: nothing converted).
Definition engine_config.hpp:138
Duration flatten_interval
Operator flatten (ControlCommand::Flatten, the control socket's flatten): how often the engine looks ...
Definition engine_config.hpp:84
Duration flatten_timeout
Definition engine_config.hpp:85
std::int64_t flatten_slippage_bps
Definition engine_config.hpp:86
int cpu
Definition engine_config.hpp:122
CapacityConfig capacity
[capacity]: the price of an order slot (core/capacity_price.hpp); mode off: none.
Definition engine_config.hpp:159
PoolHomesPlan homes
[venues.
Definition engine_config.hpp:157
std::uint32_t reduce_only_venues
[venues.<x>] reduce_only: ... for the instruments of these venues, bit per venue id.
Definition engine_config.hpp:111
bool cancel_unknown_own
[engine] cancel_unknown = "own": an open order a reconciliation (or an ack) reports that the OMS does...
Definition engine_config.hpp:90
Duration checkpoint_interval
[engine] checkpoint_s: with a journal, a checkpoint is written to it this often (StrategyStateMsg Kin...
Definition engine_config.hpp:72
Definition quote_manager.hpp:159
Definition risk_limits.hpp:18
Time primitives.