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 common::{enums::TardisExchange, parse::bar_spec_to_tardis_trade_bar_string},
23 config::TardisDataClientConfig,
24 machine::types::{
25 ReplayNormalizedRequestOptions, StreamNormalizedRequestOptions, TardisInstrumentMiniInfo,
26 },
27};
28
29#[pymethods]
30#[pyo3_stub_gen::derive::gen_stub_pymethods]
31impl TardisInstrumentMiniInfo {
32 #[new]
34 fn py_new(
35 instrument_id: InstrumentId,
36 raw_symbol: &str,
37 exchange: &str,
38 price_precision: u8,
39 size_precision: u8,
40 ) -> Self {
41 let exchange: TardisExchange = exchange
42 .parse()
43 .expect("`exchange` should be Tardis convention");
44 Self::new(
45 instrument_id,
46 Some(Ustr::from(raw_symbol)),
47 exchange,
48 price_precision,
49 size_precision,
50 )
51 }
52
53 #[getter]
54 #[pyo3(name = "instrument_id")]
55 const fn py_instrument_id(&self) -> InstrumentId {
56 self.instrument_id
57 }
58
59 #[getter]
60 #[pyo3(name = "raw_symbol")]
61 fn py_raw_symbol(&self) -> String {
62 self.raw_symbol.to_string()
63 }
64
65 #[getter]
66 #[pyo3(name = "exchange")]
67 fn py_exchange(&self) -> String {
68 self.exchange.to_string()
69 }
70
71 #[getter]
72 #[pyo3(name = "price_precision")]
73 const fn py_price_precision(&self) -> u8 {
74 self.price_precision
75 }
76
77 #[getter]
78 #[pyo3(name = "size_precision")]
79 const fn py_size_precision(&self) -> u8 {
80 self.size_precision
81 }
82}
83
84#[pyfunction(name = "bar_spec_to_tardis_trade_bar_string")]
90#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.tardis")]
91pub fn py_bar_spec_to_tardis_trade_bar_string(bar_spec: &BarSpecification) -> PyResult<String> {
92 bar_spec_to_tardis_trade_bar_string(bar_spec).map_err(to_pyvalue_err)
93}
94
95#[pymethods]
96#[pyo3_stub_gen::derive::gen_stub_pymethods]
97impl TardisDataClientConfig {
98 #[new]
100 #[pyo3(signature = (
101 api_key = None,
102 tardis_ws_url = None,
103 proxy_url = None,
104 normalize_symbols = None,
105 options = None,
106 stream_options = None,
107 ))]
108 fn py_new(
109 api_key: Option<String>,
110 tardis_ws_url: Option<String>,
111 proxy_url: Option<String>,
112 normalize_symbols: Option<bool>,
113 options: Option<Vec<ReplayNormalizedRequestOptions>>,
114 stream_options: Option<Vec<StreamNormalizedRequestOptions>>,
115 ) -> Self {
116 let defaults = Self::default();
117 Self {
118 api_key,
119 tardis_ws_url,
120 proxy_url,
121 normalize_symbols: normalize_symbols.unwrap_or(defaults.normalize_symbols),
122 book_snapshot_output: defaults.book_snapshot_output,
123 options: options.unwrap_or_default(),
124 stream_options: stream_options.unwrap_or_default(),
125 }
126 }
127
128 fn __repr__(&self) -> String {
129 format!("{self:?}")
130 }
131}