nautilus_tardis/python/
config.rs1use nautilus_core::{python::to_pyvalue_err, string::secret::SecretString};
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 ) -> PyResult<Self> {
41 let exchange: TardisExchange = exchange.parse().map_err(to_pyvalue_err)?;
42 Ok(Self::new(
43 instrument_id,
44 Some(Ustr::from(raw_symbol)),
45 exchange,
46 price_precision,
47 size_precision,
48 ))
49 }
50
51 #[getter]
52 #[pyo3(name = "instrument_id")]
53 const fn py_instrument_id(&self) -> InstrumentId {
54 self.instrument_id
55 }
56
57 #[getter]
58 #[pyo3(name = "raw_symbol")]
59 fn py_raw_symbol(&self) -> String {
60 self.raw_symbol.to_string()
61 }
62
63 #[getter]
64 #[pyo3(name = "exchange")]
65 fn py_exchange(&self) -> String {
66 self.exchange.to_string()
67 }
68
69 #[getter]
70 #[pyo3(name = "price_precision")]
71 const fn py_price_precision(&self) -> u8 {
72 self.price_precision
73 }
74
75 #[getter]
76 #[pyo3(name = "size_precision")]
77 const fn py_size_precision(&self) -> u8 {
78 self.size_precision
79 }
80}
81
82#[pyfunction(name = "bar_spec_to_tardis_trade_bar_string")]
88#[pyo3_stub_gen::derive::gen_stub_pyfunction(module = "nautilus_trader.adapters.tardis")]
89pub fn py_bar_spec_to_tardis_trade_bar_string(bar_spec: &BarSpecification) -> PyResult<String> {
90 bar_spec_to_tardis_trade_bar_string(bar_spec).map_err(to_pyvalue_err)
91}
92
93#[pymethods]
94#[pyo3_stub_gen::derive::gen_stub_pymethods]
95impl TardisDataClientConfig {
96 #[new]
98 #[pyo3(signature = (
99 api_key = None,
100 tardis_ws_url = None,
101 proxy_url = None,
102 normalize_symbols = None,
103 options = None,
104 stream_options = None,
105 extract_bbo_as_quotes = None,
106 tardis_http_url = None,
107 ))]
108 #[expect(clippy::too_many_arguments)]
109 fn py_new(
110 api_key: Option<String>,
111 tardis_ws_url: Option<String>,
112 proxy_url: Option<String>,
113 normalize_symbols: Option<bool>,
114 options: Option<Vec<ReplayNormalizedRequestOptions>>,
115 stream_options: Option<Vec<StreamNormalizedRequestOptions>>,
116 extract_bbo_as_quotes: Option<bool>,
117 tardis_http_url: Option<String>,
118 ) -> Self {
119 let defaults = Self::default();
120 Self {
121 api_key: api_key.map(SecretString::from),
122 tardis_ws_url: tardis_ws_url.map(SecretString::from),
123 tardis_http_url: tardis_http_url.map(SecretString::from),
124 proxy_url: proxy_url.map(SecretString::from),
125 normalize_symbols: normalize_symbols.unwrap_or(defaults.normalize_symbols),
126 book_snapshot_output: defaults.book_snapshot_output,
127 extract_bbo_as_quotes: extract_bbo_as_quotes.unwrap_or(defaults.extract_bbo_as_quotes),
128 options: options.unwrap_or_default(),
129 stream_options: stream_options.unwrap_or_default(),
130 }
131 }
132
133 #[getter]
134 const fn has_proxy_url(&self) -> bool {
135 self.proxy_url.is_some()
136 }
137
138 fn __repr__(&self) -> String {
139 stringify!(TardisDataClientConfig).to_string()
140 }
141}