#websocket-client #trading #cryptocurrency #blockchain

crypto-ws-client

A versatile websocket client that supports many cryptocurrency exchanges

120 stable releases

4.12.11 Feb 26, 2023
4.12.9 Dec 28, 2022
4.12.8 Oct 31, 2022
4.11.8 Jul 10, 2022
0.4.0 Dec 31, 2020

#78 in #websocket-client

39 downloads per month
Used in 2 crates (via crypto-crawler)

Apache-2.0

245KB
5.5K SLoC

crypto-ws-client

A versatile websocket client that supports many cryptocurrency exchanges.

Usage

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();
    });

    for msg in rx {
        println!("{}", msg);
    }
}

Dependencies

~10–22MB
~318K SLoC