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
.
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§
- Binance
OptionWS Client - Binance Option market
- BinanceWS
Client - BitfinexWS
Client - The WebSocket client for Bitfinex, including all markets.
- Bitget
SpotWS Client - The WebSocket client for Bitget Spot market.
- Bitget
SwapWS Client - The WebSocket client for Bitget swap markets.
- BithumbWS
Client - The WebSocket client for Bithumb.
- BitmexWS
Client - The WebSocket client for BitMEX.
- BitstampWS
Client - The WebSocket client for Bitstamp Spot market.
- Bitz
SpotWS Client - The WebSocket client for Bitz spot market.
- Bybit
InverseWS Client - Bybit Inverses markets.
- Bybit
Linear SwapWS Client - Bybit LinearSwap market.
- Coinbase
ProWS Client - The WebSocket client for CoinbasePro.
- DeribitWS
Client - The WebSocket client for Deribit.
- Dydx
SwapWS Client - The WebSocket client for dYdX perpetual markets.
- FtxWS
Client - The WebSocket client for FTX.
- Gate
Inverse FutureWS Client - The WebSocket client for Gate InverseFuture market.
- Gate
Inverse SwapWS Client - The WebSocket client for Gate InverseSwap market.
- Gate
Linear FutureWS Client - The WebSocket client for Gate LinearFuture market.
- Gate
Linear SwapWS Client - The WebSocket client for Gate LinearSwap market.
- Gate
SpotWS Client - The WebSocket client for Gate spot market.
- HuobiWS
Client - Kraken
FuturesWS Client - The WebSocket client for Kraken Futures market.
- Kraken
SpotWS Client - The WebSocket client for Kraken Spot market.
- KuCoin
SpotWS Client - The WebSocket client for KuCoin Spot market.
- KuCoin
SwapWS Client - The WebSocket client for KuCoin Swap markets.
- Mexc
SpotWS Client - MEXC Spot market.
- Mexc
SwapWS Client - MEXC Swap market.
- OkxWS
Client - The WebSocket client for OKX.
- ZbSpotWS
Client - The WebSocket client for ZB spot market.
- ZbSwapWS
Client - The WebSocket client for ZB swap market.
- ZbgSpotWS
Client - The WebSocket client for ZBG spot market.
- ZbgSwapWS
Client - The WebSocket client for ZBG swap market.
Traits§
- WSClient
- The public interface of every WebSocket client.
Type Aliases§
- Binance
InverseWS Client - Binance Coin-margined Future and Swap markets.
- Binance
LinearWS Client - Binance USDT-margined Future and Swap markets.
- Binance
SpotWS Client - Binance Spot market.
- Huobi
FutureWS Client - Huobi Future market.
- Huobi
Inverse SwapWS Client - Huobi Inverse Swap market.
- Huobi
Linear SwapWS Client - Huobi Linear Swap market.
- Huobi
OptionWS Client - Huobi Option market.
- Huobi
SpotWS Client - Huobi Spot market.