[−][src]Crate crypto_ws_client
A versatile websocket client that supports many cryptocurrency exchanges.
Example
use crypto_ws_client::{BinanceSpotWSClient, WSClient}; let mut ws_client = BinanceSpotWSClient::new(Box::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_ticker(&mut self, pairs: &String)
- subscribe_bbo(&mut self, pairs: &String)
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)
-
channel:pair
-
channel
-
A JSON string
Usually a raw_channel
is composed by a channel
and a pair
,
delimited by ,
. Sometimes the pair
is optional, for example,
instrument
of BitMEX, market.overview
of Huobi.
If a raw_channel
starts with {
, which means it is a JSON string,
then it will be sent out directly without any parsing.
More examples:
- BitMEX
trade:XBTUSD
,quote:XBTM21
,instrument
- Binance
btcusdt
,btcusd_perp
- OKEx
spot/trade:BTC-USDT
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. |
BinanceSpotWSClient | Binance Spot market. |
BitMEXWSClient | The WebSocket client for BitMEX. |
BitfinexWSClient | The WebSocket client for Bitfinex, including all markets. |
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
WSClient | The public interface of every WebSocket client. |