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