Trait crypto_ws_client::WSClient[][src]

pub trait WSClient<'a> {
    fn new(
        on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
        url: Option<&str>
    ) -> Self;
fn subscribe_trade(&self, pairs: &[String]);
fn subscribe_bbo(&self, pairs: &[String]);
fn subscribe_orderbook(&self, pairs: &[String]);
fn subscribe_orderbook_snapshot(&self, pairs: &[String]);
fn subscribe_ticker(&self, pairs: &[String]);
fn subscribe_candlestick(&self, pairs: &[String], interval: u32);
fn subscribe(&self, raw_channels: &[String]);
fn unsubscribe(&self, raw_channels: &[String]);
fn run(&self, duration: Option<u64>);
fn close(&self); }

The public interface of every WebSocket client.

Required methods

fn new(
    on_msg: Arc<Mutex<dyn FnMut(String) + Send + 'a>>,
    url: Option<&str>
) -> Self
[src]

Creates a new client.

Arguments

  • on_msg - A callback function to process original JSON messages
  • url - Optional server url, usually you don’t need specify it

fn subscribe_trade(&self, pairs: &[String])[src]

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])[src]

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 with len=1 and prec="R0" to get BBO data.

fn subscribe_orderbook(&self, pairs: &[String])[src]

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@100ms
  • Bitfinex book channel with prec=P0, frec=F0 and len=25
  • BitMEX orderBookL2_25
  • Bitstamp diff_order_book, top 100
  • CoinbasePro level2
  • Huobi depth.size_150.high_freq with data_type=incremental for contracts, mbp.150 for Spot
  • Kraken book with depth=25
  • MXC depth for Swap, symbol for Spot
  • OKEx depth_l2_tbt, top 100

fn subscribe_orderbook_snapshot(&self, pairs: &[String])[src]

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 depth20, every 1000ms
  • Bitfinex has no snapshot channel
  • BitMEX orderBook10, top 10, every tick
  • Bitstamp order_book, top 100, every 100ms
  • CoinbasePro has no snapshot channel
  • Huobi depth.step0, top 150, every 1s
  • Kraken has no snapshot channel
  • MXC depth.full for Swap, top 20, every 100ms; get.depth for Spot, full, every 26s
  • OKEx depth5, top 5, every 100ms

fn subscribe_ticker(&self, pairs: &[String])[src]

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.

fn subscribe_candlestick(&self, pairs: &[String], interval: u32)[src]

Subscribes to candlestick channels.

The candlestick channel sends OHLCV messages at interval.

interval specifies the interval of candlesticks in seconds.

Not all exchanges have candlestick channels, for example, Bitstamp and CoinbasePro.

fn subscribe(&self, raw_channels: &[String])[src]

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, BitMEX trade:XBTUSD, instrument, Bitstamp live_trades_btcusd, Huobi market.btcusdt.trade.detail, market.overview, OKEx spot/trade:BTC-USDT`.
  • channel:pair. For exchanges not supporting plain string channels, this library will split this kind of raw_channel by :, then compose a JSON string. For example, Bitfinex trades:tBTCUST, CoinbasePro matches:BTC-USD, Kraken trade:XBT/USD
  • A JSON string, supported by all exchanges. If a raw_channel starts with {, which means it is the final JSON string, thus it will be sent out directly without parsing.

fn unsubscribe(&self, raw_channels: &[String])[src]

Unsubscribes from raw channels, lower level API.

fn run(&self, duration: Option<u64>)[src]

Starts the infinite loop until time is up or the server closes the connection.

Arguments

  • duration - How many seconds to run, None means infinite.

fn close(&self)[src]

Breaks the loop and closes the connection.

Loading content...

Implementors

impl<'a> WSClient<'a> for BinanceFutureWSClient<'a>[src]

impl<'a> WSClient<'a> for BinanceInverseSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for BinanceLinearSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for BinanceOptionWSClient<'a>[src]

impl<'a> WSClient<'a> for BinanceSpotWSClient<'a>[src]

impl<'a> WSClient<'a> for BitfinexWSClient<'a>[src]

impl<'a> WSClient<'a> for BitgetSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for BithumbWSClient<'a>[src]

impl<'a> WSClient<'a> for BitmexWSClient<'a>[src]

impl<'a> WSClient<'a> for BitstampWSClient<'a>[src]

impl<'a> WSClient<'a> for BitzSpotWSClient<'a>[src]

impl<'a> WSClient<'a> for BybitInverseSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for BybitLinearSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for CoinbaseProWSClient<'a>[src]

impl<'a> WSClient<'a> for DeribitWSClient<'a>[src]

impl<'a> WSClient<'a> for FtxWSClient<'a>[src]

impl<'a> WSClient<'a> for HuobiFutureWSClient<'a>[src]

impl<'a> WSClient<'a> for HuobiInverseSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for HuobiLinearSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for HuobiOptionWSClient<'a>[src]

impl<'a> WSClient<'a> for HuobiSpotWSClient<'a>[src]

impl<'a> WSClient<'a> for KrakenWSClient<'a>[src]

impl<'a> WSClient<'a> for KuCoinSpotWSClient<'a>[src]

impl<'a> WSClient<'a> for KuCoinSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for MxcSpotWSClient<'a>[src]

impl<'a> WSClient<'a> for MxcSwapWSClient<'a>[src]

impl<'a> WSClient<'a> for OkexWSClient<'a>[src]

impl<'a> WSClient<'a> for ZbgSpotWSClient<'a>[src]

impl<'a> WSClient<'a> for ZbgSwapWSClient<'a>[src]

Loading content...