Skip to main content

nautilus_portfolio/
config.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
16use nautilus_core::serialization::default_true;
17use serde::{Deserialize, Serialize};
18
19/// Configuration for `Portfolio` instances.
20#[cfg_attr(
21    feature = "python",
22    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.live", from_py_object)
23)]
24#[cfg_attr(
25    feature = "python",
26    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.portfolio")
27)]
28#[derive(Debug, Clone, Copy, Serialize, Deserialize, bon::Builder)]
29#[serde(deny_unknown_fields)]
30pub struct PortfolioConfig {
31    /// The type of prices used for portfolio calculations, such as unrealized PnLs.
32    /// If false (default), uses quote prices if available; otherwise, last trade prices
33    /// (or falls back to bar prices if `bar_updates` is true).
34    /// If true, uses mark prices.
35    #[serde(default)]
36    #[builder(default)]
37    pub use_mark_prices: bool,
38    /// The type of exchange rates used for portfolio calculations.
39    /// If false (default), uses quote prices.
40    /// If true, uses mark prices.
41    #[serde(default)]
42    #[builder(default)]
43    pub use_mark_xrates: bool,
44    /// If external bars should be considered for updating unrealized PnLs.
45    #[serde(default = "default_true")]
46    #[builder(default = true)]
47    pub bar_updates: bool,
48    /// If calculations should be converted into each account's base currency.
49    /// This setting is only effective for accounts with a specified base currency.
50    #[serde(default = "default_true")]
51    #[builder(default = true)]
52    pub convert_to_account_base_currency: bool,
53    /// The minimum interval (milliseconds) between logging account state events for the same account.
54    /// When set, account state updates will only be logged if this much time has passed since the last log.
55    /// Useful for HFT deployments to prevent excessive logging when account states change rapidly.
56    #[serde(default)]
57    pub min_account_state_logging_interval_ms: Option<u64>,
58    /// If debug mode is active (will provide extra debug logging).
59    #[serde(default)]
60    #[builder(default)]
61    pub debug: bool,
62}
63
64impl Default for PortfolioConfig {
65    fn default() -> Self {
66        Self::builder().build()
67    }
68}