Trait crypto_ws_client::WSClient
source · pub trait WSClient {
// Required methods
fn subscribe_trade<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe_bbo<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe_orderbook<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe_orderbook_topk<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe_l3_orderbook<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe_ticker<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe_candlestick<'life0, 'life1, 'async_trait>(
&'life0 self,
symbol_interval_list: &'life1 [(String, usize)]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topics: &'life1 [(String, String)]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn unsubscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topics: &'life1 [(String, String)]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
commands: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn run<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn close<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
The public interface of every WebSocket client.
Required Methods§
sourcefn subscribe_trade<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_trade<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to trade channels.
A trade channel sends tick-by-tick trade data, which is the complete copy of a market’s trading information.
Each exchange has its own symbol formats, for example:
- BitMEX
XBTUSD
,XBTM21
- Binance
btcusdt
,btcusd_perp
- OKEx
BTC-USDT
sourcefn subscribe_bbo<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_bbo<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to BBO(best bid & offer) channels.
BBO represents best bid and offer, which is also refered to as level1 data. It is the top 1 bid and ask from the orginal orderbook, so BBO is updated per tick and non-aggregated.
Not all exchanges have the BBO channel, calling this function with these exchanges will panic.
- Binance, BitMEX, Huobi and Kraken have BBO directly.
- Bitfinex uses
book
channel withlen=1
andprec="R0"
to get BBO data.
sourcefn subscribe_orderbook<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_orderbook<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to incremental level2 orderbook channels.
An incremental level2 orderbook channel sends a snapshot followed by tick-by-tick updates.
Level2 orderbook is the raw orderbook(Level3) aggregated by price level, it is also refered to as “market by price level” data.
This function subscribes to exchange specific channels as the following:
- Binance
depth
- Bitfinex
book
channel withprec=P0
,frec=F0
andlen=25
- BitMEX
orderBookL2_25
- Bitstamp
diff_order_book
, top 100 - CoinbasePro
level2
- Huobi
depth.size_20.high_freq
withdata_type=incremental
for contracts,mbp.20
for Spot - Kraken
book
withdepth=25
- MEXC
depth
for Swap,symbol
for Spot - OKEx
depth_l2_tbt
, top 100
sourcefn subscribe_orderbook_topk<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_orderbook_topk<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to level2 orderbook snapshot channels.
A level2 orderbook snapshot channel sends a complete snapshot every interval.
This function subscribes to exchange specific channels as the following:
- Binance
depth5
, every 1000ms - Bitfinex has no snapshot channel
- BitMEX
orderBook10
, top 10, every tick - Bitstamp
order_book
, top 10, every 100ms - CoinbasePro has no snapshot channel
- Huobi
depth.step1
anddepth.step7
, top 20, every 1s - Kraken has no snapshot channel
- MEXC
depth.full
for Swap, top 20, every 100ms;get.depth
for Spot, full, every 26s - OKEx
depth5
, top 5, every 100ms
sourcefn subscribe_l3_orderbook<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_l3_orderbook<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to level3 orderebook channels.
Only bitfinex, bitstamp, coinbase_pro and kucoin have level3 orderbook channels.
The level3 orderbook is the orginal orderbook of an exchange, it is non-aggregated by price level and updated tick-by-tick.
sourcefn subscribe_ticker<'life0, 'life1, 'async_trait>(
&'life0 self,
symbols: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_ticker<'life0, 'life1, 'async_trait>( &'life0 self, symbols: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to ticker channels.
A ticker channel pushes realtime 24hr rolling window ticker messages, which contains OHLCV information.
Not all exchanges have the ticker channel, for example, BitMEX, Bitstamp, MEXC Spot, etc.
sourcefn subscribe_candlestick<'life0, 'life1, 'async_trait>(
&'life0 self,
symbol_interval_list: &'life1 [(String, usize)]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe_candlestick<'life0, 'life1, 'async_trait>( &'life0 self, symbol_interval_list: &'life1 [(String, usize)] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribes to candlestick channels.
The candlestick channel sends OHLCV messages at interval.
symbol_interval_list
is a list of symbols and intervals of
candlesticks in seconds.
Not all exchanges have candlestick channels, for example, Bitstamp and CoinbasePro.
sourcefn subscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topics: &'life1 [(String, String)]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe<'life0, 'life1, 'async_trait>( &'life0 self, topics: &'life1 [(String, String)] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Subscribe to multiple topics.
topic = channel + symbol, a topic will be converted to an
exchange-specific channel(called raw channel
).
The channel string supports SYMBOL
as a placeholder, for example,
("market.SYMBOL.trade.detail", "btcusdt")
will be converted to a raw
channel "market.btcusdt.trade.detail"
.
Examples:
- Binance:
vec![("aggTrade".to_string(), "BTCUSDT".to_string()),("ticker".to_string(), "BTCUSDT".to_string())]
- Deribit:
vec![(trades.SYMBOL.100ms".to_string(),"BTC-PERPETUAL". to_string()),(trades.SYMBOL.100ms".to_string(),"ETH-PERPETUAL". to_string())]
- Huobi:
vec![("trade.detail".to_string(), "btcusdt".to_string()),("trade.detail".to_string(), "ethusdt".to_string())]
- OKX:
vec![("trades".to_string(), "BTC-USDT".to_string()),("trades".to_string(), "ETH-USDT".to_string())]
sourcefn unsubscribe<'life0, 'life1, 'async_trait>(
&'life0 self,
topics: &'life1 [(String, String)]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn unsubscribe<'life0, 'life1, 'async_trait>( &'life0 self, topics: &'life1 [(String, String)] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Unsubscribes multiple topics.
topic = channel + symbol
sourcefn send<'life0, 'life1, 'async_trait>(
&'life0 self,
commands: &'life1 [String]
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn send<'life0, 'life1, 'async_trait>( &'life0 self, commands: &'life1 [String] ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Send raw JSON commands.
This is a low-level API for advanced users only.