[][src]Crate crypto_ws_client

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

BinanceFutureWSClient

Binance Coin-margined Future market.

BinanceInverseSwapWSClient

Binance Coin-margined Perpetual Swap market

BinanceLinearSwapWSClient

Binance USDT-margined Perpetual Swap market.

BinanceOptionWSClient

Binance Option market

BinanceSpotWSClient

Binance Spot market.

BitfinexWSClient

The WebSocket client for Bitfinex, including all markets.

BitmexWSClient

The WebSocket client for BitMEX.

BitstampWSClient

The WebSocket client for Bitstamp Spot market.

CoinbaseProWSClient

The WebSocket client for CoinbasePro.

HuobiFutureWSClient

Huobi Future market.

HuobiInverseSwapWSClient

Huobi Inverse Swap market.

HuobiLinearSwapWSClient

Huobi Linear Swap market.

HuobiOptionWSClient

Huobi Option market.

HuobiSpotWSClient

Huobi Spot market.

KrakenWSClient

The WebSocket client for Kraken.

MxcSpotWSClient

MXC Spot market.

MxcSwapWSClient

MXC Swap market.

OkexWSClient

The WebSocket client for OKEx.

Traits

Level3OrderBook

Level3 orderbook data.

WSClient

The public interface of every WebSocket client.