Trait Provider

Source
pub trait Provider:
    Send
    + Sync
    + 'static
    + Debug {
    type TradeMessage: Send + 'static;
    type DepthMessage: Send + 'static;
    type InstrumentMessage: Send + 'static;

Show 27 methods // Required methods fn name(&self) -> &'static str; fn venue(&self) -> Venue; fn config(&self) -> &ConnectionConfig; fn init<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn subscribe_trades<'life0, 'async_trait>( &'life0 self, symbols: SmallVec<[String; 8]>, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::TradeMessage>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn unsubscribe_trades<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn subscribe_orderbook<'life0, 'async_trait>( &'life0 self, symbols: SmallVec<[String; 8]>, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::DepthMessage>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn unsubscribe_orderbook<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_realtime_orderbook<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<SharedSimdOrderBook>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_instruments<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Instrument>>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_historical_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<MarketTrade>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_orderbook_snapshot<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, depth: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<OrderBookSnapshot>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn shutdown<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn start_provide_depth<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::DepthMessage>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn stop_provide_depth<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn start_provide_trade<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::TradeMessage>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn stop_provide_trade<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn is_connected<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn connection_status<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ConnectionState> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn get_stats<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ConnectionStats> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn ping<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn reset_connection<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn get_rate_limits(&self) -> Vec<RateLimit> { ... } fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn convert_exchange_timestamp(&self, exchange_timestamp: u64) -> u64 { ... } fn convert_iso8601_timestamp(&self, iso_timestamp: &str) -> Option<u64> { ... } fn current_time_nanos(&self) -> u64 { ... }
}
Expand description

High-performance provider interface for exchange connectivity Optimized for zero allocations and predictable low latency All implementations must adhere to the project’s HFT performance guidelines

Required Associated Types§

Source

type TradeMessage: Send + 'static

Exchange-specific raw message type for trades from WebSocket

Source

type DepthMessage: Send + 'static

Exchange-specific raw message type for orderbook updates from WebSocket

Source

type InstrumentMessage: Send + 'static

Exchange-specific raw message type for instrument info

Required Methods§

Source

fn name(&self) -> &'static str

Returns the exchange name as a static String

Source

fn venue(&self) -> Venue

Returns the venue enum value for this provider

Source

fn config(&self) -> &ConnectionConfig

Returns reference to the connection configuration

Source

fn init<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initialize the provider with any necessary setup steps This method should be called before using other methods

Source

fn subscribe_trades<'life0, 'async_trait>( &'life0 self, symbols: SmallVec<[String; 8]>, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::TradeMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Subscribe to trade data stream for multiple symbols Returns a channel receiver for trade messages Uses SmallVec to avoid heap allocations for small numbers of symbols

Source

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

Unsubscribe from trade data

Source

fn subscribe_orderbook<'life0, 'async_trait>( &'life0 self, symbols: SmallVec<[String; 8]>, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::DepthMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Subscribe to orderbook depth data for multiple symbols Returns a channel receiver for depth messages Uses SmallVec to avoid heap allocations for small numbers of symbols

Source

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

Unsubscribe from orderbook depth data

Source

fn get_realtime_orderbook<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<SharedSimdOrderBook>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get realtime shared orderbook for a symbol Returns a thread-safe shared orderbook that’s kept up-to-date

Source

fn get_instruments<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Box<dyn Instrument>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get all available trading instruments from the exchange

Source

fn get_historical_trades<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, limit: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<Vec<MarketTrade>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get historical trades for a symbol Optionally limit the number of trades returned

Source

fn get_orderbook_snapshot<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, depth: Option<u32>, ) -> Pin<Box<dyn Future<Output = Result<OrderBookSnapshot>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get current orderbook snapshot for a symbol Optionally specify the depth of the orderbook

Source

fn shutdown<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Close all connections and clean up resources

Provided Methods§

Source

fn start_provide_depth<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::DepthMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start providing depth data Returns a receiver for depth messages Default implementation returns error - exchanges should override

Source

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

Stop providing depth data Default implementation does nothing

Source

fn start_provide_trade<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Self::TradeMessage>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start providing trade data Returns a receiver for trade messages Default implementation returns error - exchanges should override

Source

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

Stop providing trade data Default implementation does nothing

Source

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

Check if provider is connected to exchange Default implementation returns false - exchanges should override

Source

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

Get detailed connection status Default implementation returns Disconnected - exchanges should override

Source

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

Get connection statistics for monitoring Default implementation returns empty stats - exchanges should override

Source

fn ping<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Ping the exchange to keep the connection alive Returns round-trip time in nanoseconds Default implementation returns 0 - exchanges should override

Source

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

Reset connection (force reconnect) Default implementation does nothing - exchanges should override

Source

fn get_rate_limits(&self) -> Vec<RateLimit>

Get the exchange-specific rate limits Default implementation returns empty vector - exchanges should override

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if provider is operational Returns true if the provider is functioning correctly

Source

fn convert_exchange_timestamp(&self, exchange_timestamp: u64) -> u64

High-performance timestamp conversion method Uses cached timestamp conversions when possible and provides optimized conversion when timestamps are a known format.

This method should be used in all implementations when converting exchange timestamps to ensure consistent high-performance timestamp handling across exchanges.

Source

fn convert_iso8601_timestamp(&self, iso_timestamp: &str) -> Option<u64>

Convert ISO8601 timestamp String to nanoseconds with caching for frequent values This method should be used for exchanges that provide timestamps as ISO8601 strings such as Coinbase.

Source

fn current_time_nanos(&self) -> u64

Get current time in nanoseconds from the provider’s clock This method uses the shared clock to ensure consistent timekeeping across all parts of the exchange provider.

Implementors§