Crate crypto_ws_client

Source
Expand description

A versatile websocket client that supports many cryptocurrency exchanges.

§Example

use crypto_ws_client::{BinanceSpotWSClient, WSClient};

#[tokio::main]
async fn main() {
    let (tx, rx) = std::sync::mpsc::channel();
    tokio::task::spawn(async move {
        let symbols = vec!["BTCUSDT".to_string(), "ETHUSDT".to_string()];
        let ws_client = BinanceSpotWSClient::new(tx, None).await;
        ws_client.subscribe_trade(&symbols).await;
        // run for 5 seconds
        let _ = tokio::time::timeout(std::time::Duration::from_secs(5), ws_client.run()).await;
        ws_client.close();
    });

    let mut messages = Vec::new();
    for msg in rx {
        messages.push(msg);
    }
    assert!(!messages.is_empty());
}

§High Level APIs

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

  • subscribe_trade(&self, symbols: &[String])
  • subscribe_bbo(&self, symbols: &[String])
  • subscribe_orderbook(&self, symbols: &[String])
  • subscribe_ticker(&self, symbols: &[String])
  • subscribe_candlestick(&self, symbol_interval_list: &[(String, usize)])

They are easier to use and cover most user scenarios.

§Low Level APIs

Sometimes high-level APIs can NOT meet users’ requirements, this package provides three low-level APIs:

  • subscribe(&self, topics: &[(String, String)])
  • unsubscribe(&self, topics: &[(String, String)])
  • send(&self, commands: &[String])

§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§

BinanceOptionWSClient
Binance Option market
BinanceWSClient
BitfinexWSClient
The WebSocket client for Bitfinex, including all markets.
BitgetSpotWSClient
The WebSocket client for Bitget Spot market.
BitgetSwapWSClient
The WebSocket client for Bitget swap markets.
BithumbWSClient
The WebSocket client for Bithumb.
BitmexWSClient
The WebSocket client for BitMEX.
BitstampWSClient
The WebSocket client for Bitstamp Spot market.
BitzSpotWSClient
The WebSocket client for Bitz spot market.
BybitInverseWSClient
Bybit Inverses markets.
BybitLinearSwapWSClient
Bybit LinearSwap market.
CoinbaseProWSClient
The WebSocket client for CoinbasePro.
DeribitWSClient
The WebSocket client for Deribit.
DydxSwapWSClient
The WebSocket client for dYdX perpetual markets.
FtxWSClient
The WebSocket client for FTX.
GateInverseFutureWSClient
The WebSocket client for Gate InverseFuture market.
GateInverseSwapWSClient
The WebSocket client for Gate InverseSwap market.
GateLinearFutureWSClient
The WebSocket client for Gate LinearFuture market.
GateLinearSwapWSClient
The WebSocket client for Gate LinearSwap market.
GateSpotWSClient
The WebSocket client for Gate spot market.
HuobiWSClient
KrakenFuturesWSClient
The WebSocket client for Kraken Futures market.
KrakenSpotWSClient
The WebSocket client for Kraken Spot market.
KuCoinSpotWSClient
The WebSocket client for KuCoin Spot market.
KuCoinSwapWSClient
The WebSocket client for KuCoin Swap markets.
MexcSpotWSClient
MEXC Spot market.
MexcSwapWSClient
MEXC Swap market.
OkxWSClient
The WebSocket client for OKX.
ZbSpotWSClient
The WebSocket client for ZB spot market.
ZbSwapWSClient
The WebSocket client for ZB swap market.
ZbgSpotWSClient
The WebSocket client for ZBG spot market.
ZbgSwapWSClient
The WebSocket client for ZBG swap market.

Traits§

WSClient
The public interface of every WebSocket client.

Type Aliases§

BinanceInverseWSClient
Binance Coin-margined Future and Swap markets.
BinanceLinearWSClient
Binance USDT-margined Future and Swap markets.
BinanceSpotWSClient
Binance Spot market.
HuobiFutureWSClient
Huobi Future market.
HuobiInverseSwapWSClient
Huobi Inverse Swap market.
HuobiLinearSwapWSClient
Huobi Linear Swap market.
HuobiOptionWSClient
Huobi Option market.
HuobiSpotWSClient
Huobi Spot market.