1#![warn(rustc::all)]
32#![deny(unsafe_code)]
33#![deny(nonstandard_style)]
34#![deny(missing_debug_implementations)]
35#![deny(clippy::missing_errors_doc)]
36#![deny(clippy::missing_panics_doc)]
37#![deny(rustdoc::broken_intra_doc_links)]
38
39use pyo3::prelude::*;
40
41#[pymodule]
47fn nautilus_pyo3(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
48 let sys = PyModule::import(py, "sys")?;
49 let modules = sys.getattr("modules")?;
50 let sys_modules: &Bound<'_, PyAny> = modules.downcast()?;
51 let module_name = "posei_trader.core.nautilus_pyo3";
52
53 sys_modules.set_item(module_name, m)?;
55
56 let n = "core";
57 let submodule = pyo3::wrap_pymodule!(nautilus_core::python::core);
58 m.add_wrapped(submodule)?;
59 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
60 re_export_module_attributes(m, n)?;
61
62 let n = "common";
63 let submodule = pyo3::wrap_pymodule!(nautilus_common::python::common);
64 m.add_wrapped(submodule)?;
65 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
66 re_export_module_attributes(m, n)?;
67
68 let n = "cryptography";
69 let submodule = pyo3::wrap_pymodule!(nautilus_cryptography::python::cryptography);
70 m.add_wrapped(submodule)?;
71 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
72 re_export_module_attributes(m, n)?;
73
74 let n = "model";
75 let submodule = pyo3::wrap_pymodule!(nautilus_model::python::model);
76 m.add_wrapped(submodule)?;
77 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
78 re_export_module_attributes(m, n)?;
79
80 let n = "indicators";
81 let submodule = pyo3::wrap_pymodule!(nautilus_indicators::python::indicators);
82 m.add_wrapped(submodule)?;
83 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
84 re_export_module_attributes(m, n)?;
85
86 let n = "infrastructure";
87 let submodule = pyo3::wrap_pymodule!(nautilus_infrastructure::python::infrastructure);
88 m.add_wrapped(submodule)?;
89 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
90 re_export_module_attributes(m, n)?;
91
92 let n = "network";
93 let submodule = pyo3::wrap_pymodule!(nautilus_network::python::network);
94 m.add_wrapped(submodule)?;
95 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
96 re_export_module_attributes(m, n)?;
97
98 let n = "persistence";
99 let submodule = pyo3::wrap_pymodule!(nautilus_persistence::python::persistence);
100 m.add_wrapped(submodule)?;
101 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
102 re_export_module_attributes(m, n)?;
103
104 let n = "serialization";
105 let submodule = pyo3::wrap_pymodule!(nautilus_serialization::python::serialization);
106 m.add_wrapped(submodule)?;
107 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
108 re_export_module_attributes(m, n)?;
109
110 let n = "testkit";
111 let submodule = pyo3::wrap_pymodule!(nautilus_testkit::python::testkit);
112 m.add_wrapped(submodule)?;
113 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
114 re_export_module_attributes(m, n)?;
115
116 let n = "trading";
117 let submodule = pyo3::wrap_pymodule!(nautilus_trading::python::trading);
118 m.add_wrapped(submodule)?;
119 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
120 re_export_module_attributes(m, n)?;
121
122 let n = "coinbase_intx";
125 let submodule = pyo3::wrap_pymodule!(nautilus_coinbase_intx::python::coinbase_intx);
126 m.add_wrapped(submodule)?;
127 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
128 re_export_module_attributes(m, n)?;
129
130 let n = "databento";
131 let submodule = pyo3::wrap_pymodule!(posei_traderbento::python::databento);
132 m.add_wrapped(submodule)?;
133 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
134 re_export_module_attributes(m, n)?;
135
136 let n = "tardis";
137 let submodule = pyo3::wrap_pymodule!(nautilus_tardis::python::tardis);
138 m.add_wrapped(submodule)?;
139 sys_modules.set_item(format!("{module_name}.{n}"), m.getattr(n)?)?;
140 re_export_module_attributes(m, n)?;
141
142 Ok(())
143}
144
145fn re_export_module_attributes(
146 parent_module: &Bound<'_, PyModule>,
147 submodule_name: &str,
148) -> PyResult<()> {
149 let submodule = parent_module.getattr(submodule_name)?;
150 for item_name in submodule.dir()? {
151 let item_name_str: &str = item_name.extract()?;
152 if let Ok(attr) = submodule.getattr(item_name_str) {
153 parent_module.add(item_name_str, attr)?;
154 }
155 }
156
157 Ok(())
158}