okx_http_private/
http-private.rs1use nautilus_model::identifiers::{AccountId, InstrumentId};
17use nautilus_okx::{
18 common::enums::{OKXInstrumentType, OKXPositionMode},
19 http::client::OKXHttpClient,
20};
21use tracing::level_filters::LevelFilter;
22
23#[tokio::main]
24async fn main() -> Result<(), Box<dyn std::error::Error>> {
25 tracing_subscriber::fmt()
26 .with_max_level(LevelFilter::TRACE)
27 .init();
28
29 let mut client = OKXHttpClient::from_env().unwrap();
30 let account_id = AccountId::new("OKX-001");
31
32 let inst_type = OKXInstrumentType::Swap;
33 let instruments = client.request_instruments(inst_type).await?;
34 client.add_instruments(instruments);
35
36 let resp = client.set_position_mode(OKXPositionMode::NetMode).await;
38 match resp {
39 Ok(msg) => tracing::debug!("{:?}", msg),
40 Err(e) => tracing::error!("{e:?}"),
41 }
42
43 let resp = client.request_account_state(account_id).await;
45 match resp {
46 Ok(account_state) => tracing::debug!("{:?}", account_state),
47 Err(e) => tracing::error!("{e:?}"),
48 }
49
50 let instrument_id = InstrumentId::from("BTC-USDT-SWAP.OKX");
52
53 let result = client
54 .request_order_status_reports(
55 account_id,
56 None,
57 Some(instrument_id),
58 None,
59 None,
60 false,
61 None,
62 )
63 .await;
64 match result {
65 Ok(reports) => tracing::debug!("{:?}", reports),
66 Err(e) => tracing::error!("{e:?}"),
67 }
68
69 let instrument_type = OKXInstrumentType::Swap;
70
71 let result = client
72 .request_position_status_reports(account_id, Some(instrument_type), None)
73 .await;
74 match result {
75 Ok(reports) => tracing::debug!("{:?}", reports),
76 Err(e) => tracing::error!("{e:?}"),
77 }
78
79 Ok(())
80
81 }