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
.
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 Option market
- The WebSocket client for Bitfinex, including all markets.
- The WebSocket client for Bitget Spot market.
- The WebSocket client for Bitget swap markets.
- The WebSocket client for Bithumb.
- The WebSocket client for BitMEX.
- The WebSocket client for Bitstamp Spot market.
- The WebSocket client for Bitz spot market.
- Bybit Inverses markets.
- Bybit LinearSwap market.
- The WebSocket client for CoinbasePro.
- The WebSocket client for Deribit.
- The WebSocket client for dYdX perpetual markets.
- The WebSocket client for FTX.
- The WebSocket client for Gate InverseFuture market.
- The WebSocket client for Gate InverseSwap market.
- The WebSocket client for Gate LinearFuture market.
- The WebSocket client for Gate LinearSwap market.
- The WebSocket client for Gate spot market.
- The WebSocket client for Kraken Futures market.
- The WebSocket client for Kraken Spot market.
- The WebSocket client for KuCoin Spot market.
- The WebSocket client for KuCoin Swap markets.
- MEXC Spot market.
- MEXC Swap market.
- The WebSocket client for OKX.
- The WebSocket client for ZB spot market.
- The WebSocket client for ZB swap market.
- The WebSocket client for ZBG spot market.
- The WebSocket client for ZBG swap market.
Traits
- The public interface of every WebSocket client.
Type Definitions
- Binance Coin-margined Future and Swap markets.
- Binance USDT-margined Future and Swap markets.
- Binance Spot market.
- Huobi Future market.
- Huobi Inverse Swap market.
- Huobi Linear Swap market.
- Huobi Option market.
- Huobi Spot market.