Skip to main content

Station

Struct Station 

Source
pub struct Station { /* private fields */ }
Expand description

Phase 5 Station. Unified Series<T> + DiskStore<T> plumbing under all stream classes. One multiplexer actor per SeriesKey (= exchange × account × symbol × kind). N consumers share via broadcast::channel.

Implementations§

Source§

impl Station

Source

pub fn builder() -> StationBuilder

Source

pub fn storage_root(&self) -> &Path

Source

pub fn active_streams(&self) -> usize

Source

pub fn hub(&self) -> Arc<ExchangeHub>

Shared ExchangeHub backing this Station’s connectors.

Exposed so a consumer that also needs raw REST history (e.g. a chart doing scroll-left pagination) can route backfill::fetch_history / backfill::klines_recent through the SAME connector pool the Station’s live subscriptions use — instead of dialing a second, parallel hub. One pool means one dial-wave, one rate-limit budget, one warm-up.

ExchangeHub::clone is O(1) (Arc-pooled internally).

Source

pub fn series<T: DataPoint + 'static>( &self, key: &SeriesKey, ) -> Option<Arc<RwLock<Series<T>>>>

Return a sync handle to the in-memory ring for key.

Returns Some(Arc<RwLock<Series<T>>>) when a forwarder for key is currently live (active subscription or within the 30 s grace window) and the concrete element type matches T. Returns None when no active forwarder exists for this key or when the stored type differs from T (type mismatch is silently treated as absent rather than panicking).

Render-time consumers (chart panels, dashboards) use this to peek at the running ring without awaiting an Event. The handle is independent of SubscriptionHandle::recv() — events still flow through there for state-mutation paths; this getter is read-only.

Source

pub fn register_consumer(&self, quota: ConsumerQuota) -> ConsumerHandle

Register a consumer with the given quota. Drop the returned [ConsumerHandle] to release all of the consumer’s active subscriptions atomically.

This is opt-in: Station::subscribe continues to work without quotas. A consumer that wants caps registers and uses [ConsumerHandle::subscribe]; one that does not keeps calling Station::subscribe directly.

Source

pub fn connector_events(&self) -> Receiver<Event>

A broadcast receiver for connector lifecycle events (ConnectorReady / SymbolsLoaded). Returns events emitted from any source — warmup(), on-demand subscribe-time connector init, REST exchange-info refresh.

Independent of SubscriptionHandle event streams. Capacity 256. Lag drops oldest.

Source

pub fn symbols(&self, exchange: ExchangeId) -> Vec<SymbolInfo>

Snapshot of cached SymbolInfo for exchange across all account types. Empty if warmup hasn’t yet been called or REST hasn’t completed.

Source

pub fn ws_health(&self, key: &SeriesKey) -> Option<WsHealth>

Snapshot the live health metrics for the WS forwarder backing key.

Returns None if no forwarder exists for this key (no active or grace-window subscription).

Sync, non-blocking — suitable for periodic diagnostics polls or per-frame UI overlays (latency badges). Each field is a best-effort snapshot:

  • connected: always accurate — derived from mux presence.
  • rtt_ms: None until per-connector RTT handle wiring is added (incremental; OKX is the first candidate).
  • last_message_ms: None until per-forwarder atomic timestamp wiring is added (incremental).
Source

pub fn ws_health_for_exchange(&self, exchange: ExchangeId) -> Option<WsHealth>

Aggregate health across all forwarders for exchange.

  • rtt_ms: median of non-None RTT values across forwarders.
  • last_message_ms: max of non-None last-message timestamps (most-recent message seen on any forwarder for this exchange).
  • connected: true if at least one forwarder is connected.

Returns None if there are no active forwarders for exchange.

Source

pub async fn warmup(&self, exchanges: &[ExchangeId]) -> WarmupReport

Eagerly connect to every exchange in exchanges and pre-load their full symbol list. Subscribes nothing — produces only Event::ConnectorReady (one per exchange that finishes connect_public) and Event::SymbolsLoaded (one per exchange whose REST get_exchange_info succeeds for at least one account type) on the broadcast channel returned by Station::connector_events().

Idempotent: running concurrently or repeatedly is safe. Already-connected exchanges short-circuit. Already-cached symbol lists re-broadcast from cache without REST.

Runs to completion — returns a [WarmupReport] of outcomes.

Source

pub async fn subscribe(&self, set: SubscriptionSet) -> Result<SubscribeReport>

Subscribe to every (exchange, symbol, account, stream) combination in set. Continue-on-error: per-stream failures are collected in SubscribeReport::failed and do not abort the rest of the batch.

The returned handle carries events for every stream in ok. A stream whose subscribe failed will simply not emit events through the handle.

The whole call returns Err ONLY for batch-level failures (empty set). Per-stream failures (StreamNotSupported, connect_websocket, symbol normalize) are reported via report.failed.

Trait Implementations§

Source§

impl Debug for Station

Source§

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

Formats the value using the given formatter. 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> 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: Sized + 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: Sized + 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, 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