Skip to main content

DataSource

Trait DataSource 

Source
pub trait DataSource:
    Send
    + Sync
    + 'static {
    // Required methods
    fn run<'life0, 'async_trait>(
        &'life0 self,
        sink: Sender<Vec<MarketEvent>>,
        cancel: CancellationToken,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn name(&self) -> &str;
}
Expand description

A provider of normalized market events.

A data source is responsible for:

  1. Connecting to the underlying data feed (WebSocket, REST, file).
  2. Fetching/streaming raw data.
  3. Normalizing raw data into MarketEvent variants.
  4. Sending events to the supplied sink channel.

The run method is the main execution loop. It runs until the feed is exhausted, an unrecoverable error occurs, or the CancellationToken is triggered.

Required Methods§

Source

fn run<'life0, 'async_trait>( &'life0 self, sink: Sender<Vec<MarketEvent>>, cancel: CancellationToken, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start streaming events.

The implementation sends Vec<MarketEvent> batches to the provided async channel sender. The cancel token should be polled periodically to support graceful shutdown.

Source

fn name(&self) -> &str

A human-readable name for logging and debugging.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§