scope/market/traits.rs
1//! Market client traits for fetching exchange data.
2//!
3//! These traits define the interface for fetching order books, tickers, and
4//! recent trades. They are implemented by `ConfigurableExchangeClient` and
5//! composed by the `ExchangeClient` facade.
6
7use crate::error::Result;
8use async_trait::async_trait;
9
10use super::types::{Candle, OrderBook, Ticker, Trade};
11
12/// Trait for clients that can fetch an order book snapshot.
13#[async_trait]
14pub trait OrderBookClient: Send + Sync {
15 /// Fetch the current order book for the given pair symbol.
16 async fn fetch_order_book(&self, pair_symbol: &str) -> Result<OrderBook>;
17}
18
19/// Trait for clients that can fetch a 24h ticker.
20#[async_trait]
21pub trait TickerClient: Send + Sync {
22 /// Fetch the 24h ticker for the given pair symbol.
23 async fn fetch_ticker(&self, pair_symbol: &str) -> Result<Ticker>;
24}
25
26/// Trait for clients that can fetch recent trades.
27#[async_trait]
28pub trait TradeHistoryClient: Send + Sync {
29 /// Fetch the most recent trades for the given pair symbol.
30 /// `limit` controls the maximum number of trades returned.
31 async fn fetch_recent_trades(&self, pair_symbol: &str, limit: u32) -> Result<Vec<Trade>>;
32}
33
34/// Trait for clients that can fetch OHLC (candlestick / kline) data.
35#[async_trait]
36pub trait OhlcClient: Send + Sync {
37 /// Fetch OHLC candlesticks for the given pair symbol.
38 ///
39 /// * `interval` — candle width (e.g., "1m", "5m", "15m", "1h", "4h", "1d").
40 /// * `limit` — maximum number of candles to return.
41 async fn fetch_ohlc(
42 &self,
43 pair_symbol: &str,
44 interval: &str,
45 limit: u32,
46 ) -> Result<Vec<Candle>>;
47}