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