nautilus_tardis/python/
config.rs1use 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#[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}