Trait crypto_ws_client::WSClient [−][src]
pub trait WSClient {
fn subscribe_trade(&self, pairs: &[String]);
fn subscribe_bbo(&self, pairs: &[String]);
fn subscribe_orderbook(&self, pairs: &[String]);
fn subscribe_orderbook_topk(&self, pairs: &[String]);
fn subscribe_l3_orderbook(&self, symbols: &[String]);
fn subscribe_ticker(&self, pairs: &[String]);
fn subscribe_candlestick(&self, symbol_interval_list: &[(String, usize)]);
fn subscribe(&self, raw_channels: &[String]);
fn unsubscribe(&self, raw_channels: &[String]);
fn run(&self, duration: Option<u64>);
fn close(&self);
}Expand description
The public interface of every WebSocket client.
Required methods
fn subscribe_trade(&self, pairs: &[String])
fn subscribe_trade(&self, pairs: &[String])
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 pair formats, for example:
- BitMEX
XBTUSD,XBTM21 - Binance
btcusdt,btcusd_perp - OKEx
BTC-USDT
fn subscribe_bbo(&self, pairs: &[String])
fn subscribe_bbo(&self, pairs: &[String])
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
bookchannel withlen=1andprec="R0"to get BBO data.
fn subscribe_orderbook(&self, pairs: &[String])
fn subscribe_orderbook(&self, pairs: &[String])
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
bookchannel withprec=P0,frec=F0andlen=25 - BitMEX
orderBookL2_25 - Bitstamp
diff_order_book, top 100 - CoinbasePro
level2 - Huobi
depth.size_20.high_freqwithdata_type=incrementalfor contracts,mbp.20for Spot - Kraken
bookwithdepth=25 - MXC
depthfor Swap,symbolfor Spot - OKEx
depth_l2_tbt, top 100
fn subscribe_orderbook_topk(&self, pairs: &[String])
fn subscribe_orderbook_topk(&self, pairs: &[String])
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.step1anddepth.step7, top 20, every 1s - Kraken has no snapshot channel
- MXC
depth.fullfor Swap, top 20, every 100ms;get.depthfor Spot, full, every 26s - OKEx
depth5, top 5, every 100ms
fn subscribe_l3_orderbook(&self, symbols: &[String])
fn subscribe_l3_orderbook(&self, symbols: &[String])
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.
fn subscribe_ticker(&self, pairs: &[String])
fn subscribe_ticker(&self, pairs: &[String])
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, MXC Spot, etc.
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.
Subscribes to raw channels, lower level API.
A raw_channel can be:
- A plain string, supported by Binance, BitMEX, Bitstamp, Bybit, Deribit, Huobi, OKEx, ZBG.
For example, Binance
btcusdt@aggTrade, BitMEXtrade:XBTUSD,instrument, Bitstamplive_trades_btcusd, Huobimarket.btcusdt.trade.detail,market.overview, OKExspot/trade:BTC-USDT`. - channel:pair. For exchanges not supporting plain string channels,
this library will split this kind of
raw_channelby:, then compose a JSON string. For example, Bitfinextrades:tBTCUST, CoinbasePromatches:BTC-USD, Krakentrade:XBT/USD - A JSON string, supported by all exchanges. If a
raw_channelstarts with{, which means it is the final JSON string, thus it will be sent out directly without parsing.
fn unsubscribe(&self, raw_channels: &[String])
fn unsubscribe(&self, raw_channels: &[String])
Unsubscribes from raw channels, lower level API.
Starts the infinite loop until time is up or the server closes the connection.
Arguments
duration- How many seconds to run, None means infinite.