Crate crypto_ws_client[−][src]
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
, BitMEXtrade: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, Bitfinextrades:tBTCUST
, CoinbasePromatches:BTC-USD
, Krakentrade: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
.
Aggregated | Non-Aggregated | |
---|---|---|
Updated per Tick | Inremental Level2 | Level3 |
Updated per Interval | Snapshot Level2 | Not 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
BinanceInverseWSClient | Binance Coin-margined Future and Swap markets. |
BinanceLinearWSClient | Binance USDT-margined Future and Swap markets. |
BinanceOptionWSClient | Binance Option market |
BinanceSpotWSClient | Binance Spot market. |
BitfinexWSClient | The WebSocket client for Bitfinex, including all markets. |
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. |
BybitInverseFutureWSClient | Bybit InverseFuture market. |
BybitInverseSwapWSClient | Bybit InverseSwap market. |
BybitLinearSwapWSClient | Bybit LinearSwap market. |
CoinbaseProWSClient | The WebSocket client for CoinbasePro. |
DeribitWSClient | The WebSocket client for Deribit. |
FtxWSClient | The WebSocket client for FTX. |
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. |
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. |
KuCoinSpotWSClient | The WebSocket client for KuCoin Spot market. |
KuCoinSwapWSClient | The WebSocket client for KuCoin Swap markets. |
MxcSpotWSClient | MXC Spot market. |
MxcSwapWSClient | MXC Swap market. |
OkexWSClient | The WebSocket client for OKEx. |
ZbgSpotWSClient | The WebSocket client for ZBG spot market. |
ZbgSwapWSClient | The WebSocket client for ZBG swap market. |
Traits
Level3OrderBook | Level3 orderbook data. |
WSClient | The public interface of every WebSocket client. |