pub struct EngineState {
pub status: Option<Stat<V2Status>>,
pub positions: Option<Stat<Positions>>,
pub risk: Option<Stat<Risk>>,
pub regime: Option<Stat<Regime>>,
pub live_cockpit: Option<Stat<LiveCockpit>>,
pub operator_state: Option<Stat<Snapshot>>,
pub last_heartbeat: Option<DateTime<Utc>>,
pub connection: ConnectionHealth,
}Expand description
Live mirror of the engine fields the CLI renders.
Every field is an Option<Stat<T>> — None means “we have not
seen this yet,” not “the engine doesn’t have one.” The renderer
distinguishes these states: unseen → placeholder, stale → amber
staleness badge, fresh → normal render.
Fields§
§status: Option<Stat<V2Status>>§positions: Option<Stat<Positions>>§risk: Option<Stat<Risk>>§regime: Option<Stat<Regime>>§live_cockpit: Option<Stat<LiveCockpit>>Consolidated live-readiness cockpit from GET /live/cockpit.
This is read-only operator state: preflight, immune,
reconciliation, certification, heartbeat, and local receipt
counts. It intentionally lives in the same mirror as status,
positions, risk, and regime so the full-screen TUI cockpit can
render without issuing network calls from the draw path.
operator_state: Option<Stat<Snapshot>>Operator behavioral state snapshot mirrored from the engine’s
GET /operator/state endpoint (ADR-016). The classifier runs
on the engine host; the CLI only renders. None means “never
observed” — the status bar falls back to ?.
last_heartbeat: Option<DateTime<Utc>>Most recent heartbeat timestamp from the engine’s bus poller.
Drives the freshness clock — if this stops advancing, the
status bar goes amber then red per feed thresholds.
connection: ConnectionHealthImplementations§
Source§impl EngineState
impl EngineState
pub fn new() -> Self
Returns an Arc<RwLock<Self>> ready for sharing between the
WS subscriber task and the TUI render loop.
Sourcepub fn feed_age_seconds(&self, now: DateTime<Utc>) -> Option<i64>
pub fn feed_age_seconds(&self, now: DateTime<Utc>) -> Option<i64>
Freshness of the feed, in seconds, measured against now.
Returns None if no heartbeat has been observed.
Sourcepub fn hl_rate_snapshot(&self) -> Option<HlRate>
pub fn hl_rate_snapshot(&self) -> Option<HlRate>
Hyperliquid per-minute rate the engine is reporting, if any.
Returns None when /v2/status has not been observed yet
or when the observed payload did not carry an hl_rate
field (older engine). The caller renders hl:? in both
cases — from the operator’s seat, “we haven’t heard”
and “the engine is not telling” are indistinguishable, so
the same metadata-color placeholder is the honest render.
Sourcepub fn on_ws_connected(&mut self)
pub fn on_ws_connected(&mut self)
Record that a WS connection was established. Resets the reconnect counter to zero — the one we just made is behind us.
Sourcepub fn on_ws_disconnected(&mut self)
pub fn on_ws_disconnected(&mut self)
Record that the WS dropped. Does not reset reconnect_count
— that ticks up on each attempt until one succeeds.
Sourcepub fn on_reconnect_attempt(&mut self, at: DateTime<Utc>)
pub fn on_reconnect_attempt(&mut self, at: DateTime<Utc>)
Record the start of a new reconnect attempt.
Sourcepub fn apply_status(
&mut self,
status: V2Status,
as_of: DateTime<Utc>,
source: Source,
)
pub fn apply_status( &mut self, status: V2Status, as_of: DateTime<Utc>, source: Source, )
Merge a status event into the mirror. source distinguishes
push updates (WS) from pull backfill (HTTP). The status bar
does not currently branch on Source, but the persisted
Stat<T> carries it so observability tooling + future
lints can tell which surface wrote each value.
last_heartbeat is only bumped on WS updates — HTTP
backfill is opportunistic and must not paper over a stalled
bus feed.
Sourcepub fn apply_positions(
&mut self,
positions: Positions,
as_of: DateTime<Utc>,
source: Source,
)
pub fn apply_positions( &mut self, positions: Positions, as_of: DateTime<Utc>, source: Source, )
Merge a positions event into the mirror. See
Self::apply_status for the source + heartbeat contract.
Sourcepub fn apply_risk(&mut self, risk: Risk, as_of: DateTime<Utc>, source: Source)
pub fn apply_risk(&mut self, risk: Risk, as_of: DateTime<Utc>, source: Source)
Merge a risk event into the mirror. See
Self::apply_status for the source + heartbeat contract.
Sourcepub fn apply_regime(
&mut self,
regime: Regime,
as_of: DateTime<Utc>,
source: Source,
)
pub fn apply_regime( &mut self, regime: Regime, as_of: DateTime<Utc>, source: Source, )
Merge a regime event into the mirror. See
Self::apply_status for the source + heartbeat contract.
Sourcepub fn apply_live_cockpit(&mut self, cockpit: LiveCockpit, as_of: DateTime<Utc>)
pub fn apply_live_cockpit(&mut self, cockpit: LiveCockpit, as_of: DateTime<Utc>)
Merge a live-cockpit packet fetched from the engine.
Cockpit is an HTTP-only surface today and must not bump
last_heartbeat; a healthy cockpit response does not prove
the market/event feed is alive.
Sourcepub fn apply_heartbeat(&mut self, at: DateTime<Utc>)
pub fn apply_heartbeat(&mut self, at: DateTime<Utc>)
Record a heartbeat with no payload. Bumps the freshness clock so the status-bar feed indicator stays green even during quiet market periods.
Sourcepub fn apply_operator_state(
&mut self,
snap: OperatorSnapshot,
as_of: DateTime<Utc>,
)
pub fn apply_operator_state( &mut self, snap: OperatorSnapshot, as_of: DateTime<Utc>, )
Merge an operator-state snapshot fetched from the engine.
The snapshot carries its own as_of but we also wrap it in a
Stat so the staleness clock stays uniform across every
mirror field. Note: this does not touch last_heartbeat
— operator-state lives on a slower poll cadence than the bus
feed, and we do not want it masking a stalled market feed.
Trait Implementations§
Source§impl Clone for EngineState
impl Clone for EngineState
Source§fn clone(&self) -> EngineState
fn clone(&self) -> EngineState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more