FastMM documentation
FastMM C++ API 0.6.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"
7#include "fastmm/core/fx.hpp"
8#include "fastmm/core/perp_book.hpp"
10#include "fastmm/core/risk.hpp"
11#include "fastmm/core/thread_utils.hpp"
12#include "fastmm/core/time.hpp"
13#include "fastmm/core/underlying.hpp"
14
15#include <cstdint>
16
17namespace fastmm {
18
19struct EngineConfig {
20 std::uint64_t session_id = 0;
21 std::uint64_t rng_seed = 1;
22 std::uint16_t session_epoch = 1;
23 std::uint32_t max_events_per_step = 64;
26 // Risk rejects are logged at WARN: the first of each reason, then at most one line per reason per
27 // interval with the number suppressed in between (0 logs every reject).
29 // [strategy] max_param_age_ms: quoting is disabled before the first ParamUpdate and while none
30 // was applied for this long (zero: off).
32 // [strategy] state_file / state_interval_s (strategies/hooks.hpp KeepsState): the engine takes
33 // the strategy's state() every state_interval and at the end for whoever runs it to write to
34 // state_file (Engine::take_strategy_state; empty: never), and hands initial_state to restore()
35 // once, after on_start (empty: nothing to restore). The loader reads the file, not the engine.
36 std::string state_file;
38 std::string initial_state;
39 // [strategy] state_snapshot_interval_s: with a journal, the strategy's state() and the
40 // positions are written to it this often (StrategyStateMsg; zero: never). The bytes handed to
41 // restore() are written once at the start whenever there are some.
43 // [engine] ack_timeout_ms: an order still waiting for its ack this long is force-cancelled, so a
44 // lost request cannot hold a pool slot, a max_open_orders slot and max_position exposure for
45 // good (zero: off).
47 // Operator flatten (ControlCommand::Flatten, the control socket's `flatten`): how often the
48 // engine looks at the remaining position and sends the next reduce-only slice, how long it
49 // keeps trying (zero: until it is flat or the operator stops it) and the slippage allowance a
50 // `flatten` without --max-slippage-bps uses.
53 std::int64_t flatten_slippage_bps = 25;
54 // [engine] queue_conservatism (a backtest: [backtest] queue_conservatism), in bps of 1: how much
55 // of a level's shrink ahead of our order the queue estimate (StrategyContext::queue_ahead)
56 // credits to cancels ahead of it. 10000: none.
57 std::int64_t queue_conservatism_bps = 10'000;
58 // Net PnL carried over from earlier sessions ([risk] max_loss is a budget for the deployment,
59 // not per process); fastmm-live reads it from the durable kill state (core/session_state.hpp).
61 bool quoting_enabled = true;
62 // Bit v: venue v's positions are not current until its first reconciliation ends. A live
63 // session sets it for the venues that replay executions at connect: until then the position is
64 // the store's plus whatever the replay has booked so far, and an order sized, hedged or
65 // risk-checked on it could double a hedge or pass a limit. No order is sent and quoting stays
66 // off until every such venue has reconciled (journal header await_reconcile, so a replay does
67 // the same).
68 std::uint32_t await_reconcile = 0;
69 int cpu = -1;
70 SpinMode spin_mode = SpinMode::Busy;
73 // [accounting]: the settlement currencies and their FX sources (inactive: nothing converted).
74 FxPlan fx;
75 // Maker/taker rates per instrument (fee_table, config/config.hpp), what StrategyContext::fees
76 // reports. The simulated venue charges fills with the same table; a live venue reports its own.
78 // [risk.underlying]: the underlyings with a net position limit and their instruments (inactive:
79 // none).
80 UnderlyingPlan underlying;
81 // [risk] check_balance and the initial margin rates ([[instruments]] initial_margin) the balance
82 // check and the estimate use (core/balance_book.hpp).
83 BalanceConfig balance;
84 // [accounting] mark, stale_mark_ms, stale_funding_ms: what a derivative's position is valued at
85 // and when the venue's mark, index and funding are stale (core/perp_book.hpp).
86 PerpConfig perp;
87 // [venues.<x>] pool_of: the accounts behind each venue (core/account_pool.hpp). A new order on
88 // an instrument whose venue has members goes to one of them (NewOrderRequest::account, else by
89 // balance and remaining order window), and the order keeps it.
90 PoolPlan pools;
91};
93} // namespace fastmm
Definition fees.hpp:54
Fee rates per instrument, in centi-basis-points (integer) of the fill notional.
Definition strategy.hpp:16
constexpr Duration milliseconds(std::int64_t v) noexcept
Definition time.hpp:38
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 time.hpp:22
std::uint16_t session_epoch
Definition engine_config.hpp:24
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:30
FeeTable fees
Maker/taker rates per instrument (fee_table, config/config.hpp), what StrategyContext::fees reports.
Definition engine_config.hpp:79
std::uint64_t rng_seed
Definition engine_config.hpp:23
Duration latency_publish_interval
Definition engine_config.hpp:27
Duration crossed_grace
Definition engine_config.hpp:26
UnderlyingPlan underlying
[risk.underlying]: the underlyings with a net position limit and their instruments (inactive: none).
Definition engine_config.hpp:82
PoolPlan pools
[venues.
Definition engine_config.hpp:92
RiskLimits risk
Definition engine_config.hpp:73
SpinMode spin_mode
Definition engine_config.hpp:72
std::uint64_t session_id
Definition engine_config.hpp:22
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:59
Duration ack_timeout
[engine] ack_timeout_ms: an order still waiting for its ack this long is force-cancelled,...
Definition engine_config.hpp:48
Duration state_snapshot_interval
[strategy] state_snapshot_interval_s: with a journal, the strategy's state() and the positions are wr...
Definition engine_config.hpp:44
BalanceConfig balance
[risk] check_balance and the initial margin rates ([[instruments]] initial_margin) the balance check ...
Definition engine_config.hpp:85
PerpConfig perp
[accounting] mark, stale_mark_ms, stale_funding_ms: what a derivative's position is valued at and whe...
Definition engine_config.hpp:88
std::string state_file
[strategy] state_file / state_interval_s (strategies/hooks.hpp KeepsState): the engine takes the stra...
Definition engine_config.hpp:38
bool quoting_enabled
Definition engine_config.hpp:63
std::string initial_state
Definition engine_config.hpp:40
QuoteParams quotes
Definition engine_config.hpp:74
std::uint32_t max_events_per_step
Definition engine_config.hpp:25
Duration state_interval
Definition engine_config.hpp:39
Notional pnl_carry
Net PnL carried over from earlier sessions ([risk] max_loss is a budget for the deployment,...
Definition engine_config.hpp:62
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:33
std::uint32_t await_reconcile
Bit v: venue v's positions are not current until its first reconciliation ends.
Definition engine_config.hpp:70
FxPlan fx
[accounting]: the settlement currencies and their FX sources (inactive: nothing converted).
Definition engine_config.hpp:76
Duration flatten_interval
Operator flatten (ControlCommand::Flatten, the control socket's flatten): how often the engine looks ...
Definition engine_config.hpp:53
Duration flatten_timeout
Definition engine_config.hpp:54
std::int64_t flatten_slippage_bps
Definition engine_config.hpp:55
int cpu
Definition engine_config.hpp:71
Definition quote_manager.hpp:91
Definition risk_limits.hpp:17
Time primitives.