tardis_http/
example_http.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_core::UnixNanos;
17use nautilus_model::instruments::Instrument;
18use nautilus_tardis::{
19    enums::Exchange,
20    http::{client::TardisHttpClient, query::InstrumentFilterBuilder},
21};
22
23#[tokio::main]
24async fn main() {
25    tracing_subscriber::fmt()
26        .with_max_level(tracing::Level::DEBUG)
27        .init();
28
29    let client = TardisHttpClient::new(None, None, None, true).unwrap();
30
31    // Tardis instrument definitions
32    let resp = client.instruments_info(Exchange::Binance, None, None).await;
33    println!("Received: {resp:?}");
34
35    let start = UnixNanos::from("2020-1-1");
36    let filter = InstrumentFilterBuilder::default()
37        .available_since(Some(start.into()))
38        .build()
39        .unwrap();
40
41    let resp = client
42        .instruments_info(Exchange::Binance, Some("BTCUSDT"), Some(&filter))
43        .await;
44    println!("Received: {resp:?}");
45
46    let filter = InstrumentFilterBuilder::default()
47        .instrument_type(Some(vec!["perpetual".to_string()]))
48        .build()
49        .unwrap();
50    let resp = client
51        .instruments_info(Exchange::Bitmex, Some("XBTUSD"), Some(&filter))
52        .await;
53
54    for inst in resp.unwrap() {
55        println!("{inst:?}");
56        if let Some(changes) = inst.changes {
57            for change in changes {
58                println!("Change:");
59                println!("{change:?}");
60            }
61        }
62    }
63
64    let effective = UnixNanos::from("2020-08-01");
65
66    // Nautilus instrument definitions
67    let resp = client
68        .instruments(
69            Exchange::Bitmex,
70            Some("XBTUSD"),
71            Some(&filter),
72            Some(effective),
73            None,
74        )
75        .await;
76
77    for inst in resp.unwrap() {
78        println!("{}", inst.id());
79        println!("price_increment={}", inst.price_increment());
80        println!("size_increment={}", inst.size_increment());
81        println!("multiplier={}", inst.multiplier());
82        println!("ts_event={}", inst.ts_event().to_rfc3339());
83        println!("ts_init={}", inst.ts_init().to_rfc3339());
84        println!("---------------------------");
85    }
86}