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