nautilus_test_kit/
common.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 std::path::PathBuf;
17
18use nautilus_core::paths::get_test_data_path;
19
20use crate::files::ensure_file_exists_or_download_http;
21
22#[must_use]
23pub fn get_test_data_file_path(path: &str) -> String {
24    get_test_data_path()
25        .join(path)
26        .to_str()
27        .unwrap()
28        .to_string()
29}
30
31#[must_use]
32#[allow(unused_mut)]
33pub fn get_nautilus_test_data_file_path(filename: &str) -> String {
34    let mut path = get_test_data_path().join("nautilus");
35
36    #[cfg(feature = "high-precision")]
37    {
38        path = path.join("128-bit");
39    }
40    #[cfg(not(feature = "high-precision"))]
41    {
42        path = path.join("64-bit");
43    }
44
45    path.join(filename).to_str().unwrap().to_string()
46}
47
48#[must_use]
49pub fn get_test_data_large_checksums_filepath() -> PathBuf {
50    get_test_data_path().join("large").join("checksums.json")
51}
52
53#[must_use]
54pub fn ensure_test_data_exists(filename: &str, url: &str) -> PathBuf {
55    let filepath = get_test_data_path().join("large").join(filename);
56    let checksums_filepath = get_test_data_large_checksums_filepath();
57    ensure_file_exists_or_download_http(&filepath, url, Some(&checksums_filepath)).unwrap();
58    filepath
59}
60
61#[must_use]
62pub fn ensure_data_exists_tardis_deribit_book_l2() -> PathBuf {
63    let filename = "tardis_deribit_incremental_book_L2_2020-04-01_BTC-PERPETUAL.csv.gz";
64    let base_url = "https://datasets.tardis.dev";
65    let url = format!("{base_url}/v1/deribit/incremental_book_L2/2020/04/01/BTC-PERPETUAL.csv.gz");
66    ensure_test_data_exists(filename, &url)
67}
68
69#[must_use]
70pub fn ensure_data_exists_tardis_binance_snapshot5() -> PathBuf {
71    let filename = "tardis_binance-futures_book_snapshot_5_2020-09-01_BTCUSDT.csv.gz";
72    let base_url = "https://datasets.tardis.dev";
73    let url = format!("{base_url}/v1/binance-futures/book_snapshot_5/2020/09/01/BTCUSDT.csv.gz");
74    ensure_test_data_exists(filename, &url)
75}
76
77#[must_use]
78pub fn ensure_data_exists_tardis_binance_snapshot25() -> PathBuf {
79    let filename = "tardis_binance-futures_book_snapshot_25_2020-09-01_BTCUSDT.csv.gz";
80    let base_url = "https://datasets.tardis.dev";
81    let url = format!("{base_url}/v1/binance-futures/book_snapshot_25/2020/09/01/BTCUSDT.csv.gz");
82    ensure_test_data_exists(filename, &url)
83}
84
85#[must_use]
86pub fn ensure_data_exists_tardis_huobi_quotes() -> PathBuf {
87    let filename = "tardis_huobi-dm-swap_quotes_2020-05-01_BTC-USD.csv.gz";
88    let base_url = "https://datasets.tardis.dev";
89    let url = format!("{base_url}/v1/huobi-dm-swap/quotes/2020/05/01/BTC-USD.csv.gz");
90    ensure_test_data_exists(filename, &url)
91}
92
93#[must_use]
94pub fn ensure_data_exists_tardis_bitmex_trades() -> PathBuf {
95    let filename = "tardis_bitmex_trades_2020-03-01_XBTUSD.csv.gz";
96    let base_url = "https://datasets.tardis.dev";
97    let url = format!("{base_url}/v1/bitmex/trades/2020/03/01/XBTUSD.csv.gz");
98    ensure_test_data_exists(filename, &url)
99}