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