#![allow(dead_code)]
#![allow(unused_variables)]
use std::time::Duration;
use futures_util::StreamExt;
use nautilus_bitmex::{
common::enums::BitmexEnvironment, http::client::BitmexHttpClient,
websocket::client::BitmexWebSocketClient,
};
use nautilus_network::websocket::TransportBackend;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
nautilus_common::logging::ensure_logging_initialized();
log::info!("Fetching instruments from HTTP API...");
let http_client = BitmexHttpClient::new(
None, None, None, BitmexEnvironment::Mainnet, 60, 3, 1_000, 10_000, 10_000, 10, 120, None, )
.expect("Failed to create HTTP client");
let instruments = http_client
.request_instruments(true) .await?;
log::info!("Fetched {} instruments", instruments.len());
let mut ws_client = BitmexWebSocketClient::new(
None, None,
None,
None,
5, None,
TransportBackend::default(),
None,
)
.unwrap();
ws_client.connect().await?;
tokio::time::sleep(Duration::from_millis(500)).await;
ws_client
.subscribe(vec![
"execution".to_string(),
"order".to_string(),
"margin".to_string(),
"position".to_string(),
"wallet".to_string(),
])
.await?;
let sigint = tokio::signal::ctrl_c();
tokio::pin!(sigint);
let stream = ws_client.stream();
tokio::pin!(stream);
loop {
tokio::select! {
Some(event) = stream.next() => {
log::debug!("{event:?}");
}
_ = &mut sigint => {
log::info!("Received SIGINT, closing connection...");
ws_client.close().await?;
break;
}
else => break,
}
}
Ok(())
}