nautilus_databento/python/
data.rs1use std::path::PathBuf;
19
20use nautilus_common::clients::DataClient;
21use nautilus_core::{
22 python::{to_pyruntime_err, to_pyvalue_err},
23 time::get_atomic_clock_realtime,
24};
25use nautilus_model::identifiers::{ClientId, futures::FuturesYearDigits};
26use pyo3::prelude::*;
27
28use crate::data::{DatabentoDataClient, DatabentoDataClientConfig};
29
30#[cfg(feature = "python")]
31#[pymethods]
32#[pyo3_stub_gen::derive::gen_stub_pymethods]
33impl DatabentoDataClient {
34 #[new]
40 #[pyo3(signature = (client_id, api_key, publishers_filepath, use_exchange_as_venue = true, bars_timestamp_on_close = true, futures_year_digits=None, share_class_space=true))]
41 pub fn py_new(
42 client_id: ClientId,
43 api_key: String,
44 publishers_filepath: PathBuf,
45 use_exchange_as_venue: bool,
46 bars_timestamp_on_close: bool,
47 futures_year_digits: Option<u8>,
48 share_class_space: bool,
49 ) -> PyResult<Self> {
50 let futures_year_digits = futures_year_digits
51 .map(FuturesYearDigits::try_from)
52 .transpose()
53 .map_err(to_pyvalue_err)?
54 .unwrap_or_default();
55
56 let mut config = DatabentoDataClientConfig::new(
57 api_key,
58 publishers_filepath,
59 use_exchange_as_venue,
60 bars_timestamp_on_close,
61 );
62
63 config.futures_year_digits = futures_year_digits;
64 config.share_class_space = share_class_space;
65 Self::new(client_id, config, get_atomic_clock_realtime()).map_err(to_pyruntime_err)
66 }
67
68 #[getter]
70 pub fn client_id(&self) -> ClientId {
71 DataClient::client_id(self)
72 }
73
74 #[getter]
76 pub fn is_connected(&self) -> bool {
77 DataClient::is_connected(self)
78 }
79
80 #[getter]
82 pub fn is_disconnected(&self) -> bool {
83 DataClient::is_disconnected(self)
84 }
85
86 #[getter]
88 #[pyo3(name = "api_key")]
89 pub fn py_api_key(&self) -> &str {
90 self.api_key()
91 }
92
93 #[getter]
95 #[pyo3(name = "api_key_masked")]
96 pub fn py_api_key_masked(&self) -> String {
97 self.api_key_masked()
98 }
99}