Crate crypto_ws_client[][src]

Expand description

A versatile websocket client that supports many cryptocurrency exchanges.

Example

use std::sync::{Arc, Mutex};
use crypto_ws_client::{BinanceSpotWSClient, WSClient};

let mut ws_client = BinanceSpotWSClient::new(Arc::new(Mutex::new(|msg| println!("{}", msg))), None);
let channels = vec!["btcusdt@aggTrade".to_string(), "btcusdt@depth".to_string(),];
ws_client.subscribe(&channels);
ws_client.run(Some(2)); // run for 2 seconds

High Level APIs

The following APIs are high-level APIs with ease of use:

  • subscribe_trade(&mut self, pairs: &[String])
  • subscribe_bbo(&mut self, pairs: &[String])
  • subscribe_orderbook(&mut self, pairs: &[String])
  • subscribe_ticker(&mut self, pairs: &[String])
  • subscribe_candlestick(&mut self, pairs: &[String], interval: u32)

They are easier to use and cover mostly used scenarios.

Low Level APIs

Sometimes high-level APIs can NOT meet our needs, this package provides two low-level APIs:

  • subscribe(&mut self, raw_channels: &[String])
  • unsubscribe(&mut self, raw_channels: &[String])

A raw_channel can be:

  • A plain string, supported by Binance, BitMEX, Bitstamp, Huobi, OKEx. 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.

OrderBook Data Categories

Each orderbook has three properties: aggregation, frequency and depth.

AggregatedNon-Aggregated
Updated per TickInremental Level2Level3
Updated per IntervalSnapshot Level2Not Usefull
  • Level1 data is non-aggregated, updated per tick, top 1 bid & ask from the original orderbook.
  • Level2 data is aggregated by price level, updated per tick.
  • Level3 data is the original orderbook, which is not aggregated.

Structs

Binance Coin-margined Future and Swap markets.

Binance USDT-margined Future and Swap markets.

Binance Option market

Binance Spot market.

The WebSocket client for Bitfinex, including all markets.

The WebSocket client for Bitget swap markets.

The WebSocket client for Bithumb.

The WebSocket client for BitMEX.

The WebSocket client for Bitstamp Spot market.

The WebSocket client for Bitz spot market.

Bybit InverseFuture market.

Bybit InverseSwap market.

Bybit LinearSwap market.

The WebSocket client for CoinbasePro.

The WebSocket client for Deribit.

The WebSocket client for FTX.

The WebSocket client for Gate InverseFuture market.

The WebSocket client for Gate InverseSwap market.

The WebSocket client for Gate LinearFuture market.

The WebSocket client for Gate LinearSwap market.

The WebSocket client for Gate spot market.

Huobi Future market.

Huobi Inverse Swap market.

Huobi Linear Swap market.

Huobi Option market.

Huobi Spot market.

The WebSocket client for Kraken.

The WebSocket client for KuCoin Spot market.

The WebSocket client for KuCoin Swap markets.

MXC Spot market.

MXC Swap market.

The WebSocket client for OKEx.

The WebSocket client for ZBG spot market.

The WebSocket client for ZBG swap market.

Traits

Level3 orderbook data.

The public interface of every WebSocket client.