nautilus_blockchain/python/
mod.rs1#![allow(
19 clippy::missing_errors_doc,
20 reason = "errors documented on underlying Rust methods"
21)]
22
23pub mod config;
24
25#[cfg(feature = "hypersync")]
26pub mod factories;
27
28#[cfg(feature = "hypersync")]
29use nautilus_core::python::{to_pyruntime_err, to_pyvalue_err};
30#[cfg(feature = "hypersync")]
31use nautilus_system::{
32 factories::{ClientConfig, DataClientFactory},
33 get_global_pyo3_registry,
34};
35use pyo3::prelude::*;
36
37#[cfg(feature = "hypersync")]
39#[allow(clippy::needless_pass_by_value)] fn extract_blockchain_factory(
41 py: Python<'_>,
42 factory: Py<PyAny>,
43) -> PyResult<Box<dyn DataClientFactory>> {
44 match factory.extract::<crate::factories::BlockchainDataClientFactory>(py) {
45 Ok(concrete_factory) => Ok(Box::new(concrete_factory)),
46 Err(e) => Err(to_pyvalue_err(format!(
47 "Failed to extract BlockchainDataClientFactory: {e}"
48 ))),
49 }
50}
51
52#[cfg(feature = "hypersync")]
54#[allow(clippy::needless_pass_by_value)] fn extract_blockchain_config(py: Python<'_>, config: Py<PyAny>) -> PyResult<Box<dyn ClientConfig>> {
56 match config.extract::<crate::config::BlockchainDataClientConfig>(py) {
57 Ok(concrete_config) => Ok(Box::new(concrete_config)),
58 Err(e) => Err(to_pyvalue_err(format!(
59 "Failed to extract BlockchainDataClientConfig: {e}"
60 ))),
61 }
62}
63
64#[pymodule]
70pub fn blockchain(_: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
71 m.add_class::<crate::config::BlockchainDataClientConfig>()?;
72 m.add_class::<crate::config::DexPoolFilters>()?;
73 #[cfg(feature = "hypersync")]
74 m.add_class::<crate::factories::BlockchainDataClientFactory>()?;
75
76 #[cfg(feature = "hypersync")]
78 {
79 let registry = get_global_pyo3_registry();
80
81 if let Err(e) = registry
82 .register_factory_extractor("BLOCKCHAIN".to_string(), extract_blockchain_factory)
83 {
84 return Err(to_pyruntime_err(format!(
85 "Failed to register blockchain factory extractor: {e}"
86 )));
87 }
88
89 if let Err(e) = registry.register_config_extractor(
90 "BlockchainDataClientConfig".to_string(),
91 extract_blockchain_config,
92 ) {
93 return Err(to_pyruntime_err(format!(
94 "Failed to register blockchain config extractor: {e}"
95 )));
96 }
97 }
98
99 Ok(())
100}