Skip to main content

CandleSource

Trait CandleSource 

Source
pub trait CandleSource:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn poll<'life0, 'life1, 'async_trait>(
        &'life0 self,
        symbol: &'life1 Symbol,
        interval: Duration,
        limit: usize,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Candle>, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
}
Expand description

Periodic candle source — separate from MarketSource because candle polling has a fundamentally different shape (pull, paced) than streaming events (push, unbounded).

Spot-only adapters don’t need to implement this; the framework will only spawn a candle poller when one is wired via Bot::with_candle_poller. Futures adapters with native candle endpoints (KuCoin, Binance, Bybit, …) implement it directly.

§Example

A fixed-series source useful for backtests and replays. The framework’s poller will dedupe by Candle::time, so repeated polls returning the same head are safe.

use std::time::Duration;
use async_trait::async_trait;
use rustrade_core::{Candle, CandleSource, Result, Symbol};

struct FixedCandles {
    candles: Vec<Candle>,
}

#[async_trait]
impl CandleSource for FixedCandles {
    fn name(&self) -> &str { "fixed" }
    async fn poll(
        &self,
        _symbol: &Symbol,
        _interval: Duration,
        limit: usize,
    ) -> Result<Vec<Candle>> {
        Ok(self.candles.iter().rev().take(limit).rev().copied().collect())
    }
}

Required Methods§

Source

fn name(&self) -> &str

Short identifier for logging — typically the exchange name.

Source

fn poll<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 Symbol, interval: Duration, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<Candle>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Fetch up to limit of the most recent completed candles for symbol at the given interval. Implementors return them in chronological order (oldest first). If the exchange’s native endpoint returns newest-first, sort before returning.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§