use anyhow::{Context, Result};
use tokio::time::{Duration, sleep};
use tracing::info;
use binance_sdk::config::ConfigurationWebsocketStreams;
use binance_sdk::spot::{SpotWsStreams, websocket_streams::DiffBookDepthParams};
#[tokio::main]
async fn main() -> Result<()> {
let ws_streams_conf = ConfigurationWebsocketStreams::builder().build()?;
let ws_streams_client = SpotWsStreams::production(ws_streams_conf);
let connection = ws_streams_client
.connect()
.await
.context("Failed to connect to WebSocket Streams")?;
let params = DiffBookDepthParams::builder("bnbusdt".to_string()).build()?;
let stream = connection
.diff_book_depth(params)
.await
.context("Failed to subscribe to the stream")?;
stream.on_message(|data| {
info!("{:?}", data);
});
sleep(Duration::from_secs(20)).await;
connection
.disconnect()
.await
.context("Failed to disconnect WebSocket client")?;
Ok(())
}