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