okx_http_private/
http-private.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use 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    // Set position mode
37    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    // Request account state
44    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    // Request orders history
51    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    // let params = GetOrderParamsBuilder::default()
82    //     .symbol("XBTUSD".to_string())
83    //     .build()?;
84    // match client.get_orders(params).await {
85    //     Ok(resp) => tracing::debug!("{:?}", resp),
86    //     Err(e) => tracing::error!("{e:?}"),
87    // }
88    //
89    // Ok(())
90}