okx_http_public/http-public.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::{data::BarType, identifiers::InstrumentId};
17use nautilus_okx::{common::enums::OKXInstrumentType, http::client::OKXHttpClient};
18use tracing::level_filters::LevelFilter;
19
20#[tokio::main]
21async fn main() -> Result<(), Box<dyn std::error::Error>> {
22 tracing_subscriber::fmt()
23 .with_max_level(LevelFilter::TRACE)
24 .init();
25
26 let mut client = OKXHttpClient::from_env().unwrap();
27
28 // Request instruments
29 let inst_type = OKXInstrumentType::Swap;
30 let instruments = client.request_instruments(inst_type).await?;
31 client.add_instruments(instruments);
32
33 let inst_type = OKXInstrumentType::Spot;
34 let instruments = client.request_instruments(inst_type).await?;
35 client.add_instruments(instruments);
36
37 // Request mark price
38 let instrument_id = InstrumentId::from("BTC-USDT-SWAP.OKX");
39
40 let resp = client.request_mark_price(instrument_id).await;
41 match resp {
42 Ok(resp) => tracing::debug!("{:?}", resp),
43 Err(e) => tracing::error!("{e:?}"),
44 }
45
46 // Request index price
47 let instrument_id = InstrumentId::from("BTC-USDT.OKX");
48
49 let resp = client.request_index_price(instrument_id).await;
50 match resp {
51 Ok(resp) => tracing::debug!("{:?}", resp),
52 Err(e) => tracing::error!("{e:?}"),
53 }
54
55 // Request trades
56 let resp = client.request_trades(instrument_id, None, None, None).await;
57 match resp {
58 Ok(resp) => tracing::debug!("{:?}", resp),
59 Err(e) => tracing::error!("{e:?}"),
60 }
61
62 // Request bars
63 let bar_type = BarType::from("BTC-USDT-SWAP.OKX-1-MINUTE-LAST-EXTERNAL");
64
65 let resp = client.request_bars(bar_type, None, None, None).await;
66 match resp {
67 Ok(resp) => tracing::debug!("{:?}", resp),
68 Err(e) => tracing::error!("{e:?}"),
69 }
70
71 // let params = GetPositionTiersParamsBuilder::default()
72 // .instrument_type(OKXInstrumentType::Swap)
73 // .trade_mode(OKXTradeMode::Isolated)
74 // .instrument_family("BTC-USD")
75 // .build()?;
76 // match client.http_get_position_tiers(params).await {
77 // Ok(resp) => tracing::debug!("{:?}", resp),
78 // Err(e) => tracing::error!("{e:?}"),
79 // }
80 //
81
82 //
83 // let params = GetPositionsParamsBuilder::default()
84 // .instrument_type(OKXInstrumentType::Swap)
85 // .build()?;
86 // match client.http_get_positions(params).await {
87 // Ok(resp) => tracing::debug!("{:?}", resp),
88 // Err(e) => tracing::error!("{e:?}"),
89 // }
90 //
91 // let params = GetPositionsHistoryParamsBuilder::default()
92 // .instrument_type(OKXInstrumentType::Swap)
93 // .build()?;
94 // match client.http_get_position_history(params).await {
95 // Ok(resp) => tracing::debug!("{:?}", resp),
96 // Err(e) => tracing::error!("{e:?}"),
97 // }
98
99 Ok(())
100}