use anyhow::{Context, Result};
use std::env;
use tracing::info;
use binance_sdk::config::ConfigurationWebsocketApi;
use binance_sdk::logger;
use binance_sdk::spot::{SpotWsApi, websocket_api::SessionLogoutParams};
#[tokio::main]
async fn main() -> Result<()> {
logger::init();
let api_key = env::var("API_KEY").expect("API_KEY must be set in the environment");
let api_secret = env::var("API_SECRET").expect("API_SECRET must be set in the environment");
let ws_api_conf = ConfigurationWebsocketApi::builder()
.api_key(api_key)
.api_secret(api_secret)
.build()?;
let ws_api_client = SpotWsApi::production(ws_api_conf);
let connection = ws_api_client
.connect()
.await
.context("Failed to connect to WebSocket API")?;
let params = SessionLogoutParams::default();
let response = connection
.session_logout(params)
.await
.context("session_logout request failed")?;
for (idx, resp) in response.into_iter().enumerate() {
info!(response_index = idx, ?resp.rate_limits, "session_logon rate limits");
let data = resp.data()?;
info!(response_index = idx, ?data, "session_logon data");
}
connection
.disconnect()
.await
.context("Failed to disconnect WebSocket client")?;
Ok(())
}