nautilus_blockchain/python/
mod.rs1pub mod config;
19
20#[cfg(feature = "hypersync")]
21pub mod factories;
22
23#[cfg(feature = "hypersync")]
24use nautilus_common::factories::{ClientConfig, DataClientFactory};
25#[cfg(feature = "hypersync")]
26use nautilus_core::python::{to_pyruntime_err, to_pyvalue_err};
27#[cfg(feature = "hypersync")]
28use nautilus_system::get_global_pyo3_registry;
29use pyo3::prelude::*;
30
31#[cfg(feature = "hypersync")]
33#[expect(clippy::needless_pass_by_value)] fn extract_blockchain_factory(
35 py: Python<'_>,
36 factory: Py<PyAny>,
37) -> PyResult<Box<dyn DataClientFactory>> {
38 match factory.extract::<crate::factories::BlockchainDataClientFactory>(py) {
39 Ok(concrete_factory) => Ok(Box::new(concrete_factory)),
40 Err(e) => Err(to_pyvalue_err(format!(
41 "Failed to extract BlockchainDataClientFactory: {e}"
42 ))),
43 }
44}
45
46#[cfg(feature = "hypersync")]
48#[expect(clippy::needless_pass_by_value)] fn extract_blockchain_config(py: Python<'_>, config: Py<PyAny>) -> PyResult<Box<dyn ClientConfig>> {
50 match config.extract::<crate::config::BlockchainDataClientConfig>(py) {
51 Ok(concrete_config) => Ok(Box::new(concrete_config)),
52 Err(e) => Err(to_pyvalue_err(format!(
53 "Failed to extract BlockchainDataClientConfig: {e}"
54 ))),
55 }
56}
57
58#[pymodule]
64pub fn blockchain(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
65 m.add_class::<crate::config::BlockchainDataClientConfig>()?;
66 m.add_class::<crate::config::DexPoolFilters>()?;
67 #[cfg(feature = "hypersync")]
68 m.add_class::<crate::factories::BlockchainDataClientFactory>()?;
69
70 #[cfg(feature = "hypersync")]
72 {
73 let registry = get_global_pyo3_registry();
74
75 if let Err(e) = registry
76 .register_factory_extractor("BLOCKCHAIN".to_string(), extract_blockchain_factory)
77 {
78 return Err(to_pyruntime_err(format!(
79 "Failed to register blockchain factory extractor: {e}"
80 )));
81 }
82
83 if let Err(e) = registry.register_config_extractor(
84 "BlockchainDataClientConfig".to_string(),
85 extract_blockchain_config,
86 ) {
87 return Err(to_pyruntime_err(format!(
88 "Failed to register blockchain config extractor: {e}"
89 )));
90 }
91 }
92
93 Ok(())
94}