Skip to main content

nautilus_tardis/python/
config.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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::python::to_pyvalue_err;
17use nautilus_model::{data::BarSpecification, identifiers::InstrumentId};
18use pyo3::prelude::*;
19use ustr::Ustr;
20
21use crate::{
22    enums::TardisExchange, machine::types::TardisInstrumentMiniInfo,
23    parse::bar_spec_to_tardis_trade_bar_string,
24};
25
26#[pymethods]
27impl TardisInstrumentMiniInfo {
28    #[new]
29    fn py_new(
30        instrument_id: InstrumentId,
31        raw_symbol: String,
32        exchange: String,
33        price_precision: u8,
34        size_precision: u8,
35    ) -> PyResult<Self> {
36        let exchange: TardisExchange = exchange
37            .parse()
38            .expect("`exchange` should be Tardis convention");
39        Ok(Self::new(
40            instrument_id,
41            Some(Ustr::from(&raw_symbol)),
42            exchange,
43            price_precision,
44            size_precision,
45        ))
46    }
47
48    #[getter]
49    #[pyo3(name = "instrument_id")]
50    const fn py_instrument_id(&self) -> InstrumentId {
51        self.instrument_id
52    }
53
54    #[getter]
55    #[pyo3(name = "raw_symbol")]
56    fn py_raw_symbol(&self) -> String {
57        self.raw_symbol.to_string()
58    }
59
60    #[getter]
61    #[pyo3(name = "exchange")]
62    fn py_exchange(&self) -> String {
63        self.exchange.to_string()
64    }
65
66    #[getter]
67    #[pyo3(name = "price_precision")]
68    const fn py_price_precision(&self) -> u8 {
69        self.price_precision
70    }
71
72    #[getter]
73    #[pyo3(name = "size_precision")]
74    const fn py_size_precision(&self) -> u8 {
75        self.size_precision
76    }
77}
78
79/// Converts a bar specification to a Tardis trade bar string.
80///
81/// # Errors
82///
83/// Returns an error if the bar specification cannot be converted to a Tardis format.
84#[pyfunction(name = "bar_spec_to_tardis_trade_bar_string")]
85pub fn py_bar_spec_to_tardis_trade_bar_string(bar_spec: &BarSpecification) -> PyResult<String> {
86    bar_spec_to_tardis_trade_bar_string(bar_spec).map_err(to_pyvalue_err)
87}