Skip to main content

JanusState

Struct JanusState 

Source
pub struct JanusState {
    pub config: Config,
    pub signal_bus: SignalBus,
    pub market_data_bus: MarketDataBus,
    /* private fields */
}
Expand description

Shared application state accessible by all modules

Fields§

§config: Config

Configuration

§signal_bus: SignalBus

Signal broadcast bus for inter-module communication

§market_data_bus: MarketDataBus

Market data broadcast bus for live data streaming (Data → Forward)

The Data module publishes normalised MarketDataEvents here when live market data ingestion is active. The Forward module subscribes to consume them for indicator calculation and strategy-driven signal generation.

Implementations§

Source§

impl JanusState

Source

pub async fn new(config: Config) -> Result<Self>

Create new application state.

Services start in ServiceState::Standby — the API module comes up immediately but processing modules (Forward, Backward, CNS, Data) will block on [wait_for_services_start] until an explicit start command is issued through the API or web interface.

Source

pub async fn current_regime(&self) -> Option<String>

Get the most recently published market-regime label.

Returns the value most recently written via [set_current_regime], or None if no producer has reported a regime yet. Used by the JFLOW-A session metrics reporter.

Source

pub async fn set_current_regime(&self, regime: impl Into<String>)

Publish the latest market-regime label.

Intended to be called by the brain pipeline / regime detector as new decisions land. Overwrites whatever was there before — the field is a snapshot, not a history.

Source

pub async fn current_threat(&self) -> Option<f64>

Get the most recently published amygdala threat / fear level.

A scalar in 0.0..=1.0 (higher = more fear), or None if no producer has reported one yet. Consumed by position guidance to escalate under stress. Kept as a plain f64 so janus-core stays free of any dependency on the neuromorphic crate that produces it.

Source

pub async fn set_current_threat(&self, fear: f64)

Publish the latest amygdala threat / fear level.

Intended to be called by the brain pipeline as new amygdala assessments land. Snapshot semantics, like [set_current_regime].

Source

pub async fn set_affinity_recorder(&self, recorder: Box<dyn AffinityRecorder>)

Install a strategy-affinity recorder.

Called once by the forward service after its TradingPipeline is constructed, so the API’s position-close handler can feed realized outcomes into affinity learning. Replaces any previously installed recorder.

Source

pub async fn has_affinity_recorder(&self) -> bool

Whether an affinity recorder is installed (for diagnostics / logging).

Source

pub async fn record_affinity_outcome( &self, strategy: &str, asset: &str, pnl: f64, is_winner: bool, rr_ratio: Option<f64>, ) -> bool

Record a closed trade into the affinity tracker, if a recorder is installed. No-op otherwise. Returns whether the outcome was recorded.

Source

pub async fn set_log_level_controller( &self, controller: Box<dyn LogLevelController>, )

Install a runtime log-level controller.

Called once from main() after init_logging() returns. The controller is then available to the API via set_log_level and current_log_filter.

Source

pub async fn set_log_level(&self, filter_str: &str) -> Result<(), String>

Change the runtime log filter.

Delegates to the installed LogLevelController. Returns an error if no controller has been installed yet.

Source

pub async fn current_log_filter(&self) -> Option<String>

Returns the current log filter string, if a controller is installed.

Source

pub fn uptime_seconds(&self) -> u64

Get uptime in seconds

Source

pub fn is_shutdown_requested(&self) -> bool

Check if shutdown has been requested

Source

pub fn request_shutdown(&self)

Request shutdown

Source

pub async fn shutdown(&self) -> Result<()>

Perform graceful shutdown

Source

pub fn start_services(&self) -> bool

Transition processing services to ServiceState::Running.

All modules blocked on [wait_for_services_start] will proceed. Returns true if the state actually changed.

Source

pub fn stop_services(&self) -> bool

Transition processing services to ServiceState::Stopped.

Modules should check [are_services_active] in their hot loops and wind down gracefully when it returns false. Returns true if the state actually changed.

Source

pub fn service_state(&self) -> ServiceState

Returns the current ServiceState.

Source

pub fn are_services_active(&self) -> bool

Returns true when processing modules should be actively running.

Source

pub async fn wait_for_services_start(&self) -> bool

Block until services are started (state becomes ServiceState::Running) or a shutdown is requested.

Returns true if services were started, false if a shutdown was requested while still waiting.

Source

pub fn subscribe_service_state(&self) -> Receiver<ServiceState>

Subscribe to service-state changes.

Useful for modules that need to react to stop commands mid-loop.

Source

pub async fn register_module_health( &self, name: impl Into<String>, healthy: bool, message: Option<String>, )

Register a module’s health status

Source

pub async fn get_module_health(&self) -> Vec<ModuleHealth>

Get all module health statuses

Source

pub async fn all_modules_healthy(&self) -> bool

Check if all modules are healthy

Source

pub fn increment_signals_generated(&self)

Increment signals generated counter

Source

pub fn signals_generated(&self) -> u64

Get signals generated count

Source

pub fn increment_signals_persisted(&self)

Increment signals persisted counter

Source

pub fn signals_persisted(&self) -> u64

Get signals persisted count

Source

pub async fn redis_client(&self) -> Result<Client>

Get or create the Redis client handle.

This is intentionally cheap — redis::Client::open only parses the URL; it does not open a TCP connection. Callers obtain an actual connection via client.get_multiplexed_async_connection().

Source

pub async fn probe_redis(&self)

Probe Redis connectivity and update the janus_redis_connected Prometheus gauge.

Call once at startup (from main()) and optionally from periodic health-check loops. The method never returns an error — it logs warnings and sets the gauge to 0 on failure so the process can continue booting even if Redis is temporarily unavailable.

Source

pub async fn health_status(&self) -> HealthStatus

Get comprehensive health status

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> 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, 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<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