Skip to main content

FillSource

Trait FillSource 

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

Received fill events from the exchange’s private feed.

Adapters implement this to route fills into the bot. Most exchanges push both order updates and fill events; this trait abstracts the “fill” part.

§Example

An in-memory fill source backed by a tokio::sync::mpsc channel — useful for tests and replay drivers.

use async_trait::async_trait;
use rustrade_core::{Fill, FillSource};
use tokio::sync::mpsc;
use tokio::sync::Mutex;

struct ChannelFills {
    rx: Mutex<mpsc::UnboundedReceiver<Fill>>,
}

#[async_trait]
impl FillSource for ChannelFills {
    async fn next_fill(&self) -> Option<Fill> {
        self.rx.lock().await.recv().await
    }
}

Required Methods§

Source

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

Await the next fill. 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§