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