18 std::string_view contents);
30 std::string_view bytes,
31 std::uint32_t version);
34 std::uint32_t& version);
45 bool* wrapped =
nullptr);
68[[nodiscard]]
constexpr std::int64_t
utc_day_start(std::int64_t wall_ns)
noexcept {
69 constexpr std::int64_t kDay = 86'400'000'000'000;
70 return wall_ns - ((wall_ns % kDay) + kDay) % kDay;
75inline bool start_loss_period(KillState& s, std::int64_t period_start_ns)
noexcept {
76 if (s.period_start_ns == period_start_ns)
return false;
79 s.period_start_ns = period_start_ns;
86 [[nodiscard]]
static std::string
default_path(std::string_view journal_dir,
87 std::string_view engine_name);
static std::string default_path(std::string_view journal_dir, std::string_view engine_name)
"<journal_dir>/<engine name>.kill".
static Result< KillState, std::string > load(const std::string &path)
A missing file is a cleared state; a file that cannot be read or parsed is an error.
static Result< void, std::string > clear(const std::string &path)
Removes the file (an operator clearing a latched trip and the loss budget with it).
static Result< void, std::string > store(const std::string &path, const KillState &s)
The 16-bit session epoch is the high half of every ClientOrderId, so two sessions that share one woul...
Definition session_state.hpp:40
static Result< std::uint16_t, std::string > next_epoch(const std::string &path, bool *wrapped=nullptr)
Reads the durable counter, increments it, writes it back and returns the epoch to use (1....
Minimal expected<T, E>: the hot path never throws, it returns Result.
Fixed<Tag>: int64 fixed point with a global 1e-8 scale (ADR-0001).
Definition strategy.hpp:23
Result< bool, std::string > load_strategy_state(const std::string &path, std::string &out)
The strategy state file ([strategy] state_file, written by write_file_atomic): its bytes,...
constexpr std::int64_t utc_day_start(std::int64_t wall_ns) noexcept
00:00 UTC of the day wall_ns falls in.
Definition session_state.hpp:70
bool start_loss_period(KillState &s, std::int64_t period_start_ns) noexcept
Starts the loss budget's period that holds wall_ns when the state counts an earlier one: realized and...
Definition session_state.hpp:77
KillReason
Why a kill switch (global or one venue's) was tripped.
Definition enums.hpp:603
Fixed< struct NotionalTag > Notional
Definition fixed_point.hpp:334
Result< void, std::string > write_strategy_state(const std::string &path, std::string_view bytes, std::uint32_t version)
The [strategy] state_file as the engine's state() bytes go into it: a 16-byte head ("FMSTATE1",...
Result< void, std::string > write_file_atomic(const std::string &path, std::string_view contents)
Writes contents to path atomically: <path>.tmp, fsync, rename, fsync of the directory.
Result< bool, std::string > read_strategy_state(const std::string &path, std::string &out, std::uint32_t &version)
Cumulative risk state across sessions.
Definition session_state.hpp:54
Notional carry() const noexcept
The carry [risk] max_loss is measured against, on top of the running session's PnL.
Definition session_state.hpp:66
Notional realized
Definition session_state.hpp:57
std::int64_t updated_ns
wall clock of the last write
Definition session_state.hpp:60
KillReason reason
Definition session_state.hpp:56
std::int64_t period_start_ns
[risk] max_loss_period = "utc_day": the 00:00 UTC (wall ns) realized and fees count from; 0 for "tota...
Definition session_state.hpp:63
bool latched
a max-loss trip is latched: refuse to start until an operator clears it
Definition session_state.hpp:55
std::uint64_t sessions
Definition session_state.hpp:59
Notional fees
Definition session_state.hpp:58