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, Bitstamplive_trades_btcusd, Huobimarket.btcusdt.trade.detail,market.overview, OKExspot/trade:BTC-USDT`. - channel:pair. For exchanges not supporting plain string channels,
this library will split this kind of
raw_channelby:, 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_channelstarts 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
| 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. |
| BitgetSwapWSClient | The WebSocket client for Bitget swap markets. |
| BitmexWSClient | The WebSocket client for BitMEX. |
| BitstampWSClient | The WebSocket client for Bitstamp Spot market. |
| BitzSpotWSClient | The WebSocket client for Bitz spot 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. |
| 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. |
| ZbgSpotWSClient | The WebSocket client for ZBG spot market. |
| ZbgSwapWSClient | The WebSocket client for ZBG spot market. |
Traits
| Level3OrderBook | Level3 orderbook data. |
| WSClient | The public interface of every WebSocket client. |