Skip to main content

nautilus_portfolio/python/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Python bindings from [PyO3](https://pyo3.rs).
17
18use pyo3::pymethods;
19
20use crate::config::PortfolioConfig;
21
22#[pyo3_stub_gen::derive::gen_stub_pymethods]
23#[pymethods]
24impl PortfolioConfig {
25    /// Configuration for `Portfolio` instances.
26    #[new]
27    #[pyo3(signature = (use_mark_prices=None, use_mark_xrates=None, bar_updates=None, convert_to_account_base_currency=None, min_account_state_logging_interval_ms=None, debug=None))]
28    fn py_new(
29        use_mark_prices: Option<bool>,
30        use_mark_xrates: Option<bool>,
31        bar_updates: Option<bool>,
32        convert_to_account_base_currency: Option<bool>,
33        min_account_state_logging_interval_ms: Option<u64>,
34        debug: Option<bool>,
35    ) -> Self {
36        let default = Self::default();
37        Self {
38            use_mark_prices: use_mark_prices.unwrap_or(default.use_mark_prices),
39            use_mark_xrates: use_mark_xrates.unwrap_or(default.use_mark_xrates),
40            bar_updates: bar_updates.unwrap_or(default.bar_updates),
41            convert_to_account_base_currency: convert_to_account_base_currency
42                .unwrap_or(default.convert_to_account_base_currency),
43            min_account_state_logging_interval_ms,
44            debug: debug.unwrap_or(default.debug),
45        }
46    }
47
48    fn __repr__(&self) -> String {
49        format!("{self:?}")
50    }
51
52    fn __str__(&self) -> String {
53        format!("{self:?}")
54    }
55
56    #[getter]
57    fn use_mark_prices(&self) -> bool {
58        self.use_mark_prices
59    }
60
61    #[getter]
62    fn use_mark_xrates(&self) -> bool {
63        self.use_mark_xrates
64    }
65
66    #[getter]
67    fn bar_updates(&self) -> bool {
68        self.bar_updates
69    }
70
71    #[getter]
72    fn convert_to_account_base_currency(&self) -> bool {
73        self.convert_to_account_base_currency
74    }
75
76    #[getter]
77    fn min_account_state_logging_interval_ms(&self) -> Option<u64> {
78        self.min_account_state_logging_interval_ms
79    }
80
81    #[getter]
82    fn debug(&self) -> bool {
83        self.debug
84    }
85}