Skip to main content

EventSource

Trait EventSource 

Source
pub trait EventSource:
    Send
    + Sync
    + 'static {
    // Required method
    fn next_event<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Option<MarketDataEvent>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Received order-book / market-data events from the exchange’s public feed.

§Example

A simple channel-backed event source — typical for tests that push scripted ticks/candles into the bot.

use async_trait::async_trait;
use rustrade_core::{EventSource, MarketDataEvent};
use tokio::sync::mpsc;
use tokio::sync::Mutex;

struct ChannelEvents {
    rx: Mutex<mpsc::UnboundedReceiver<MarketDataEvent>>,
}

#[async_trait]
impl EventSource for ChannelEvents {
    async fn next_event(&self) -> Option<MarketDataEvent> {
        self.rx.lock().await.recv().await
    }
}

Required Methods§

Source

fn next_event<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<MarketDataEvent>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Await the next event. Returns None when the stream ends.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§