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::TardisExchange,
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
33        .instruments_info(TardisExchange::Binance, None, None)
34        .await;
35    println!("Received: {resp:?}");
36
37    let start = UnixNanos::from("2020-1-1");
38    let filter = InstrumentFilterBuilder::default()
39        .available_since(Some(start.into()))
40        .build()
41        .unwrap();
42
43    let resp = client
44        .instruments_info(TardisExchange::Binance, Some("BTCUSDT"), Some(&filter))
45        .await;
46    println!("Received: {resp:?}");
47
48    let filter = InstrumentFilterBuilder::default()
49        .instrument_type(Some(vec!["perpetual".to_string()]))
50        .build()
51        .unwrap();
52    let resp = client
53        .instruments_info(TardisExchange::Bitmex, Some("XBTUSD"), Some(&filter))
54        .await;
55
56    for inst in resp.unwrap() {
57        println!("{inst:?}");
58        if let Some(changes) = inst.changes {
59            for change in changes {
60                println!("Change:");
61                println!("{change:?}");
62            }
63        }
64    }
65
66    let effective = UnixNanos::from("2020-08-01");
67
68    // Nautilus instrument definitions
69    let resp = client
70        .instruments(
71            TardisExchange::Bitmex,
72            Some("XBTUSD"),
73            Some(&filter),
74            None,
75            None,
76            None,
77            Some(effective),
78            None,
79        )
80        .await;
81
82    for inst in resp.unwrap() {
83        println!("{}", inst.id());
84        println!("price_increment={}", inst.price_increment());
85        println!("size_increment={}", inst.size_increment());
86        println!("multiplier={}", inst.multiplier());
87        println!("ts_event={}", inst.ts_event().to_rfc3339());
88        println!("ts_init={}", inst.ts_init().to_rfc3339());
89        println!("---------------------------");
90    }
91}