nautilus_databento/python/
factories.rs1use std::path::PathBuf;
19
20use indexmap::IndexMap;
21use nautilus_core::{python::to_pyruntime_err, time::get_atomic_clock_realtime};
22use nautilus_model::identifiers::ClientId;
23use pyo3::prelude::*;
24
25use crate::{
26 data::{DatabentoDataClient, DatabentoDataClientConfig},
27 factories::DatabentoDataClientFactory,
28};
29
30#[pymethods]
31#[pyo3_stub_gen::derive::gen_stub_pymethods]
32impl DatabentoDataClientConfig {
33 #[new]
35 #[pyo3(signature = (api_key, publishers_filepath, use_exchange_as_venue=false, bars_timestamp_on_close=true, venue_dataset_map=None, historical_base_url=None, live_gateway_addr=None))]
36 fn py_new(
37 api_key: String,
38 publishers_filepath: PathBuf,
39 use_exchange_as_venue: bool,
40 bars_timestamp_on_close: bool,
41 venue_dataset_map: Option<IndexMap<String, String>>,
42 historical_base_url: Option<String>,
43 live_gateway_addr: Option<String>,
44 ) -> Self {
45 let mut config = Self::new(
46 api_key,
47 publishers_filepath,
48 use_exchange_as_venue,
49 bars_timestamp_on_close,
50 );
51
52 if let Some(venue_dataset_map) = venue_dataset_map {
53 config.venue_dataset_map = venue_dataset_map;
54 }
55
56 config.historical_base_url = historical_base_url;
57 config.live_gateway_addr = live_gateway_addr;
58
59 config
60 }
61
62 fn __repr__(&self) -> String {
63 format!("{self:?}")
64 }
65}
66
67#[pymethods]
68#[pyo3_stub_gen::derive::gen_stub_pymethods]
69impl DatabentoDataClientFactory {
70 #[new]
72 fn py_new() -> Self {
73 Self
74 }
75
76 #[pyo3(name = "name")]
77 fn py_name(&self) -> &'static str {
78 "DATABENTO"
79 }
80
81 #[staticmethod]
87 #[pyo3(name = "create_live_data_client")]
88 #[pyo3(signature = (client_id, api_key, publishers_filepath, use_exchange_as_venue = true, bars_timestamp_on_close = true))]
89 pub fn py_create_live_data_client(
90 client_id: ClientId,
91 api_key: String,
92 publishers_filepath: PathBuf,
93 use_exchange_as_venue: bool,
94 bars_timestamp_on_close: bool,
95 ) -> PyResult<DatabentoDataClient> {
96 Self::create_live_data_client(
97 client_id,
98 api_key,
99 publishers_filepath,
100 use_exchange_as_venue,
101 bars_timestamp_on_close,
102 get_atomic_clock_realtime(),
103 )
104 .map_err(to_pyruntime_err)
105 }
106}