nautilus_databento/python/
mod.rs1#![expect(
19 clippy::missing_errors_doc,
20 reason = "errors documented on underlying Rust methods"
21)]
22
23pub mod arrow;
24pub mod enums;
25pub mod historical;
26pub mod loader;
27pub mod types;
28
29#[cfg(feature = "live")]
30pub mod data;
31#[cfg(feature = "live")]
32pub mod factories;
33#[cfg(feature = "live")]
34pub mod live;
35
36#[cfg(feature = "live")]
37use nautilus_common::factories::{ClientConfig, DataClientFactory};
38use nautilus_core::python::{to_pyruntime_err, to_pyvalue_err};
39use nautilus_system::get_global_pyo3_registry;
40use pyo3::prelude::*;
41
42#[cfg(feature = "live")]
43use crate::{
44 common::DATABENTO, data::DatabentoDataClientConfig, factories::DatabentoDataClientFactory,
45};
46
47#[cfg(feature = "live")]
48#[expect(clippy::needless_pass_by_value)]
49fn extract_databento_data_factory(
50 py: Python<'_>,
51 factory: Py<PyAny>,
52) -> PyResult<Box<dyn DataClientFactory>> {
53 match factory.extract::<DatabentoDataClientFactory>(py) {
54 Ok(f) => Ok(Box::new(f)),
55 Err(e) => Err(to_pyvalue_err(format!(
56 "Failed to extract DatabentoDataClientFactory: {e}"
57 ))),
58 }
59}
60
61#[cfg(feature = "live")]
62#[expect(clippy::needless_pass_by_value)]
63fn extract_databento_data_config(
64 py: Python<'_>,
65 config: Py<PyAny>,
66) -> PyResult<Box<dyn ClientConfig>> {
67 match config.extract::<DatabentoDataClientConfig>(py) {
68 Ok(c) => Ok(Box::new(c)),
69 Err(e) => Err(to_pyvalue_err(format!(
70 "Failed to extract DatabentoDataClientConfig: {e}"
71 ))),
72 }
73}
74
75#[pymodule]
83pub fn databento(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
84 m.add_class::<super::enums::DatabentoStatisticType>()?;
85 m.add_class::<super::enums::DatabentoStatisticUpdateAction>()?;
86 m.add_class::<super::types::DatabentoPublisher>()?;
87 m.add_class::<super::types::DatabentoStatistics>()?;
88 m.add_class::<super::types::DatabentoImbalance>()?;
89 m.add_class::<super::loader::DatabentoDataLoader>()?;
90 m.add_class::<historical::DatabentoHistoricalClient>()?;
91 m.add_function(wrap_pyfunction!(arrow::get_databento_arrow_schema_map, m)?)?;
92 m.add_function(wrap_pyfunction!(
93 arrow::py_databento_imbalance_to_arrow_record_batch_bytes,
94 m
95 )?)?;
96 m.add_function(wrap_pyfunction!(
97 arrow::py_databento_imbalance_from_arrow_record_batch_bytes,
98 m
99 )?)?;
100 m.add_function(wrap_pyfunction!(
101 arrow::py_databento_statistics_to_arrow_record_batch_bytes,
102 m
103 )?)?;
104 m.add_function(wrap_pyfunction!(
105 arrow::py_databento_statistics_from_arrow_record_batch_bytes,
106 m
107 )?)?;
108
109 #[cfg(feature = "live")]
110 m.add_class::<crate::data::DatabentoDataClient>()?;
111 #[cfg(feature = "live")]
112 m.add_class::<DatabentoDataClientConfig>()?;
113 #[cfg(feature = "live")]
114 m.add_class::<DatabentoDataClientFactory>()?;
115 #[cfg(feature = "live")]
116 m.add_class::<live::DatabentoLiveClient>()?;
117 #[cfg(feature = "live")]
118 m.add_class::<types::DatabentoSubscriptionAck>()?;
119
120 #[cfg(feature = "live")]
121 {
122 let registry = get_global_pyo3_registry();
123
124 if let Err(e) = registry
125 .register_factory_extractor(DATABENTO.to_string(), extract_databento_data_factory)
126 {
127 return Err(to_pyruntime_err(format!(
128 "Failed to register Databento data factory extractor: {e}"
129 )));
130 }
131
132 if let Err(e) = registry.register_config_extractor(
133 "DatabentoDataClientConfig".to_string(),
134 extract_databento_data_config,
135 ) {
136 return Err(to_pyruntime_err(format!(
137 "Failed to register Databento data config extractor: {e}"
138 )));
139 }
140 }
141
142 Ok(())
143}