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// -------------------------------------------------------------------------------------------------
1516//! Python bindings from [PyO3](https://pyo3.rs).
1718pub mod config;
19pub mod csv;
20pub mod enums;
21pub mod http;
22pub mod machine;
2324use std::str::FromStr;
2526use nautilus_core::python::to_pyvalue_err;
27use pyo3::prelude::*;
28use ustr::Ustr;
2930use super::enums::{Exchange, InstrumentType};
31use crate::parse::normalize_symbol_str;
3233#[pyfunction(name = "tardis_normalize_symbol_str")]
34#[pyo3(signature = (symbol, exchange, instrument_type, is_inverse=None))]
35pub fn py_tardis_normalize_symbol_str(
36 symbol: String,
37 exchange: String,
38 instrument_type: String,
39 is_inverse: Option<bool>,
40) -> PyResult<String> {
41let symbol = Ustr::from(&symbol);
42let exchange = Exchange::from_str(&exchange).map_err(to_pyvalue_err)?;
43let instrument_type = InstrumentType::from_str(&instrument_type).map_err(to_pyvalue_err)?;
4445Ok(normalize_symbol_str(symbol, &exchange, &instrument_type, is_inverse).to_string())
46}
4748/// Loaded as nautilus_pyo3.tardis
49///
50/// # Errors
51///
52/// Returns a `PyErr` if registering any module components fails.
53#[pymodule]
54pub fn tardis(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
55 m.add_class::<super::machine::types::InstrumentMiniInfo>()?;
56 m.add_class::<super::machine::types::ReplayNormalizedRequestOptions>()?;
57 m.add_class::<super::machine::types::StreamNormalizedRequestOptions>()?;
58 m.add_class::<super::machine::TardisMachineClient>()?;
59 m.add_class::<super::http::client::TardisHttpClient>()?;
60 m.add_function(wrap_pyfunction!(
61 enums::py_tardis_exchange_from_venue_str,
62 m
63 )?)?;
64 m.add_function(wrap_pyfunction!(
65 config::py_bar_spec_to_tardis_trade_bar_string,
66 m
67 )?)?;
68 m.add_function(wrap_pyfunction!(machine::py_run_tardis_machine_replay, m)?)?;
69 m.add_function(wrap_pyfunction!(csv::py_load_tardis_deltas, m)?)?;
70 m.add_function(wrap_pyfunction!(
71 csv::py_load_tardis_depth10_from_snapshot5,
72 m
73 )?)?;
74 m.add_function(wrap_pyfunction!(
75 csv::py_load_tardis_depth10_from_snapshot25,
76 m
77 )?)?;
78 m.add_function(wrap_pyfunction!(csv::py_load_tardis_quotes, m)?)?;
79 m.add_function(wrap_pyfunction!(csv::py_load_tardis_trades, m)?)?;
80 m.add_function(wrap_pyfunction!(py_tardis_normalize_symbol_str, m)?)?;
8182Ok(())
83}