crypto_ws_client/
lib.rs

1//! A versatile websocket client that supports many cryptocurrency exchanges.
2//!
3//! ## Example
4//!
5//! ```
6//! use crypto_ws_client::{BinanceSpotWSClient, WSClient};
7//!
8//! #[tokio::main]
9//! async fn main() {
10//!     let (tx, rx) = std::sync::mpsc::channel();
11//!     tokio::task::spawn(async move {
12//!         let symbols = vec!["BTCUSDT".to_string(), "ETHUSDT".to_string()];
13//!         let ws_client = BinanceSpotWSClient::new(tx, None).await;
14//!         ws_client.subscribe_trade(&symbols).await;
15//!         // run for 5 seconds
16//!         let _ = tokio::time::timeout(std::time::Duration::from_secs(5), ws_client.run()).await;
17//!         ws_client.close();
18//!     });
19//!
20//!     let mut messages = Vec::new();
21//!     for msg in rx {
22//!         messages.push(msg);
23//!     }
24//!     assert!(!messages.is_empty());
25//! }
26//! ```
27//! ## High Level APIs
28//!
29//! The following APIs are high-level APIs with ease of use:
30//!
31//! * `subscribe_trade(&self, symbols: &[String])`
32//! * `subscribe_bbo(&self, symbols: &[String])`
33//! * `subscribe_orderbook(&self, symbols: &[String])`
34//! * `subscribe_ticker(&self, symbols: &[String])`
35//! * `subscribe_candlestick(&self, symbol_interval_list: &[(String, usize)])`
36//!
37//! They are easier to use and cover most user scenarios.
38//!
39//! ## Low Level APIs
40//!
41//! Sometimes high-level APIs can NOT meet users' requirements, this package
42//! provides three low-level APIs:
43//!
44//! * `subscribe(&self, topics: &[(String, String)])`
45//! * `unsubscribe(&self, topics: &[(String, String)])`
46//! * `send(&self, commands: &[String])`
47//!
48//! ## OrderBook Data Categories
49//!
50//! Each orderbook has three properties: `aggregation`, `frequency` and `depth`.
51//!
52//! |                      | Aggregated        | Non-Aggregated |
53//! | -------------------- | ----------------- | -------------- |
54//! | Updated per Tick     | Inremental Level2 | Level3         |
55//! | Updated per Interval | Snapshot Level2   | Not Usefull    |
56//!
57//! * Level1 data is non-aggregated, updated per tick, top 1 bid & ask from the
58//!   original orderbook.
59//! * Level2 data is aggregated by price level, updated per tick.
60//! * Level3 data is the original orderbook, which is not aggregated.
61
62mod clients;
63mod common;
64
65pub use common::ws_client::WSClient;
66
67pub use clients::{
68    binance::*, binance_option::*, bitfinex::*, bitget::*, bithumb::*, bitmex::*, bitstamp::*,
69    bitz::*, bybit::*, coinbase_pro::*, deribit::*, dydx::*, ftx::*, gate::*, huobi::*, kraken::*,
70    kucoin::*, mexc::*, okx::*, zb::*, zbg::*,
71};