Skip to main content

EngineState

Struct EngineState 

Source
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: ConnectionHealth

Implementations§

Source§

impl EngineState

Source

pub fn new() -> Self

Source

pub fn shared() -> Arc<RwLock<Self>>

Returns an Arc<RwLock<Self>> ready for sharing between the WS subscriber task and the TUI render loop.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn on_reconnect_attempt(&mut self, at: DateTime<Utc>)

Record the start of a new reconnect attempt.

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.

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.

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.

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> EngineState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EngineState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EngineState

Source§

fn default() -> EngineState

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more