Skip to content

Commit 84dde50

Browse files
committed
Continue BitMEX adapter execution
1 parent 47e01d9 commit 84dde50

File tree

12 files changed

+689
-526
lines changed

12 files changed

+689
-526
lines changed

crates/adapters/bitmex/bin/http.rs

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,13 @@
1313
// limitations under the License.
1414
// -------------------------------------------------------------------------------------------------
1515

16+
// Under development
17+
#![allow(dead_code)]
18+
#![allow(unused_variables)]
19+
1620
use std::env;
1721

18-
use nautilus_bitmex::http::{
19-
client::BitmexHttpClient,
20-
parse::parse_instrument_any,
21-
query::{
22-
GetExecutionParamsBuilder, GetOrderParamsBuilder, GetPositionParamsBuilder,
23-
GetTradeParamsBuilder,
24-
},
25-
};
26-
use nautilus_core::time::get_atomic_clock_realtime;
27-
use nautilus_model::{identifiers::InstrumentId, instruments::any::InstrumentAny};
22+
use nautilus_bitmex::http::client::BitmexHttpClient;
2823
use tracing::level_filters::LevelFilter;
2924

3025
#[tokio::main]
@@ -37,69 +32,5 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3732
let api_secret = env::var("BITMEX_API_SECRET").expect("environment variable should be set");
3833
let client = BitmexHttpClient::new(None, Some(api_key), Some(api_secret), false, None);
3934

40-
match client.get_instruments(false).await {
41-
Ok(resp) => {
42-
tracing::debug!("{:?}", resp);
43-
let ts_init = get_atomic_clock_realtime().get_time_ns();
44-
let mut instruments: Vec<InstrumentAny> = Vec::new();
45-
for def in resp {
46-
tracing::debug!("Parsing {def:?}");
47-
if let Some(inst) = parse_instrument_any(&def, ts_init) {
48-
instruments.push(inst);
49-
} else {
50-
tracing::warn!(
51-
"Did not parse: symbol={}, type={}",
52-
def.symbol,
53-
def.instrument_type,
54-
);
55-
}
56-
}
57-
}
58-
Err(e) => tracing::error!("{e:?}"),
59-
}
60-
61-
let instrument_id = InstrumentId::from("XBTUSD.BITMEX");
62-
63-
match client.get_instrument(&instrument_id.symbol).await {
64-
Ok(resp) => tracing::debug!("{:?}", resp),
65-
Err(e) => tracing::error!("{e:?}"),
66-
}
67-
68-
let resp = client.get_wallet().await;
69-
match resp {
70-
Ok(instrument) => tracing::debug!("{:?}", instrument),
71-
Err(e) => tracing::error!("{e:?}"),
72-
}
73-
74-
let params = GetOrderParamsBuilder::default()
75-
.symbol("XBTUSD".to_string())
76-
.build()?;
77-
match client.get_orders(params).await {
78-
Ok(resp) => tracing::debug!("{:?}", resp),
79-
Err(e) => tracing::error!("{e:?}"),
80-
}
81-
82-
let params = GetTradeParamsBuilder::default()
83-
.symbol("XBTUSD".to_string())
84-
.build()?;
85-
match client.get_trades(params).await {
86-
Ok(resp) => tracing::debug!("{:?}", resp),
87-
Err(e) => tracing::error!("{e:?}"),
88-
}
89-
90-
let params = GetExecutionParamsBuilder::default()
91-
.symbol("XBTUSD".to_string())
92-
.build()?;
93-
match client.get_executions(params).await {
94-
Ok(resp) => tracing::debug!("{:?}", resp),
95-
Err(e) => tracing::error!("{e:?}"),
96-
}
97-
98-
let params = GetPositionParamsBuilder::default().build()?;
99-
match client.get_positions(params).await {
100-
Ok(resp) => tracing::debug!("{:?}", resp),
101-
Err(e) => tracing::error!("{e:?}"),
102-
}
103-
10435
Ok(())
10536
}

crates/adapters/bitmex/bin/ws-data.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616
use std::env;
1717

1818
use futures_util::StreamExt;
19-
use nautilus_bitmex::{
20-
http::{client::BitmexHttpClient, parse::parse_instrument_any},
21-
websocket::client::BitmexWebSocketClient,
22-
};
23-
use nautilus_core::time::get_atomic_clock_realtime;
19+
use nautilus_bitmex::{http::client::BitmexHttpClient, websocket::client::BitmexWebSocketClient};
2420
use nautilus_model::{data::bar::BarType, identifiers::InstrumentId};
25-
use tokio::{pin, signal, time::Duration};
21+
use tokio::time::Duration;
2622
use tracing::level_filters::LevelFilter;
2723

2824
#[tokio::main]
@@ -63,15 +59,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6359
Some(60), // timeout_secs
6460
);
6561

66-
let instruments_result = http_client
67-
.get_instruments(true) // active_only
62+
let instruments = http_client
63+
.request_instruments(true) // active_only
6864
.await?;
6965

70-
let ts_init = get_atomic_clock_realtime().get_time_ns();
71-
let instruments: Vec<_> = instruments_result
72-
.iter()
73-
.filter_map(|inst| parse_instrument_any(inst, ts_init))
74-
.collect();
7566
tracing::info!("Fetched {} instruments", instruments.len());
7667

7768
// Create WebSocket client
@@ -199,8 +190,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
199190
tracing::info!("Press CTRL+C to stop");
200191

201192
// Create a future that completes on CTRL+C
202-
let sigint = signal::ctrl_c();
203-
pin!(sigint);
193+
let sigint = tokio::signal::ctrl_c();
194+
tokio::pin!(sigint);
204195

205196
let stream = ws_client.stream();
206197
tokio::pin!(stream); // Pin the stream to allow polling in the loop

crates/adapters/bitmex/bin/ws-exec.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818
#![allow(unused_variables)]
1919

2020
use futures_util::StreamExt;
21-
use nautilus_bitmex::{
22-
http::{client::BitmexHttpClient, parse::parse_instrument_any},
23-
websocket::client::BitmexWebSocketClient,
24-
};
25-
use nautilus_core::time::get_atomic_clock_realtime;
26-
use tokio::{pin, signal, time::Duration};
21+
use nautilus_bitmex::{http::client::BitmexHttpClient, websocket::client::BitmexWebSocketClient};
22+
use tokio::time::Duration;
2723
use tracing::level_filters::LevelFilter;
2824

2925
#[tokio::main]
@@ -41,15 +37,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4137
Some(60), // timeout_secs
4238
);
4339

44-
let instruments_result = http_client
45-
.get_instruments(true) // active_only
40+
let instruments = http_client
41+
.request_instruments(true) // active_only
4642
.await?;
4743

48-
let ts_init = get_atomic_clock_realtime().get_time_ns();
49-
let instruments: Vec<_> = instruments_result
50-
.iter()
51-
.filter_map(|inst| parse_instrument_any(inst, ts_init))
52-
.collect();
5344
tracing::info!("Fetched {} instruments", instruments.len());
5445

5546
let mut ws_client = BitmexWebSocketClient::new(
@@ -78,8 +69,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7869
.await?;
7970

8071
// Create a future that completes on CTRL+C
81-
let sigint = signal::ctrl_c();
82-
pin!(sigint);
72+
let sigint = tokio::signal::ctrl_c();
73+
tokio::pin!(sigint);
8374

8475
let stream = ws_client.stream();
8576
tokio::pin!(stream); // Pin the stream to allow polling in the loop

0 commit comments

Comments
 (0)