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.adapters.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 extract_bbo_as_quotes = None,
108 ))]
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 ) -> Self {
118 let defaults = Self::default();
119 Self {
120 api_key,
121 tardis_ws_url,
122 proxy_url,
123 normalize_symbols: normalize_symbols.unwrap_or(defaults.normalize_symbols),
124 book_snapshot_output: defaults.book_snapshot_output,
125 extract_bbo_as_quotes: extract_bbo_as_quotes.unwrap_or(defaults.extract_bbo_as_quotes),
126 options: options.unwrap_or_default(),
127 stream_options: stream_options.unwrap_or_default(),
128 }
129 }
130
131 fn __repr__(&self) -> String {
132 format!("{self:?}")
133 }
134}