use anyhow::{Context, Result};
use tokio::time::{Duration, sleep};
use tracing::info;
use binance_sdk::alpha::{AlphaWsStreams, websocket_streams::TickerStreamParams};
use binance_sdk::config::ConfigurationWebsocketStreams;
use binance_sdk::logger;
#[tokio::main]
async fn main() -> Result<()> {
logger::init();
let ws_streams_conf = ConfigurationWebsocketStreams::builder().build()?;
let ws_streams_client = AlphaWsStreams::production(ws_streams_conf);
let connection = ws_streams_client
.connect()
.await
.context("Failed to connect to WebSocket Streams")?;
let params = TickerStreamParams::builder("alpha_116usdt".to_string()).build()?;
let stream = connection
.ticker_stream(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(())
}