Skip to main content

nautilus_sandbox/
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
16//! Configuration for sandbox execution client.
17
18use ahash::AHashMap;
19use nautilus_execution::matching_engine::config::OrderMatchingEngineConfig;
20use nautilus_model::{
21    enums::{AccountType, BookType, OmsType},
22    identifiers::{AccountId, InstrumentId, TraderId, Venue},
23    types::{Currency, Money},
24};
25use rust_decimal::Decimal;
26use serde::{Deserialize, Serialize};
27
28/// Configuration for `SandboxExecutionClient` instances.
29#[derive(Debug, Clone, Serialize, Deserialize, bon::Builder)]
30#[serde(deny_unknown_fields)]
31#[cfg_attr(
32    feature = "python",
33    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.sandbox", from_py_object)
34)]
35#[cfg_attr(
36    feature = "python",
37    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.sandbox")
38)]
39pub struct SandboxExecutionClientConfig {
40    /// The trader ID for this client.
41    #[builder(default = TraderId::from("SANDBOX-001"))]
42    pub trader_id: TraderId,
43    /// The account ID for this client.
44    #[builder(default = AccountId::from("SANDBOX-001"))]
45    pub account_id: AccountId,
46    /// The venue for this sandbox execution client.
47    #[builder(default = Venue::new("SANDBOX"))]
48    pub venue: Venue,
49    /// The starting balances for this sandbox venue.
50    #[builder(default)]
51    pub starting_balances: Vec<Money>,
52    /// The base currency for this venue (None for multi-currency).
53    pub base_currency: Option<Currency>,
54    /// The order management system type used by the exchange.
55    #[builder(default = OmsType::Netting)]
56    pub oms_type: OmsType,
57    /// The account type for the client.
58    #[builder(default = AccountType::Margin)]
59    pub account_type: AccountType,
60    /// The account default leverage (for margin accounts).
61    #[builder(default = Decimal::ONE)]
62    pub default_leverage: Decimal,
63    /// Per-instrument leverage overrides.
64    #[builder(default)]
65    pub leverages: AHashMap<InstrumentId, Decimal>,
66    /// The order book type for the matching engine.
67    #[builder(default = BookType::L1_MBP)]
68    pub book_type: BookType,
69    /// If True, account balances won't change (frozen).
70    #[builder(default)]
71    pub frozen_account: bool,
72    /// If bars should be processed by the matching engine (and move the market).
73    #[builder(default = true)]
74    pub bar_execution: bool,
75    /// If trades should be processed by the matching engine (and move the market).
76    #[builder(default = true)]
77    pub trade_execution: bool,
78    /// If stop orders are rejected on submission if trigger price is in the market.
79    #[builder(default = true)]
80    pub reject_stop_orders: bool,
81    /// If orders with GTD time in force will be supported by the venue.
82    #[builder(default = true)]
83    pub support_gtd_orders: bool,
84    /// If contingent orders will be supported/respected by the venue.
85    #[builder(default = true)]
86    pub support_contingent_orders: bool,
87    /// If venue position IDs will be generated on order fills.
88    #[builder(default = true)]
89    pub use_position_ids: bool,
90    /// If venue order IDs and position IDs will be random UUID4's.
91    /// Trade IDs are always deterministic and not affected by this flag.
92    #[builder(default)]
93    pub use_random_ids: bool,
94    /// If the `reduce_only` execution instruction on orders will be honored.
95    #[builder(default = true)]
96    pub use_reduce_only: bool,
97}
98
99impl SandboxExecutionClientConfig {
100    /// Creates an [`OrderMatchingEngineConfig`] from this sandbox config.
101    #[must_use]
102    pub fn to_matching_engine_config(&self) -> OrderMatchingEngineConfig {
103        OrderMatchingEngineConfig::builder()
104            .bar_execution(self.bar_execution)
105            .trade_execution(self.trade_execution)
106            .reject_stop_orders(self.reject_stop_orders)
107            .support_gtd_orders(self.support_gtd_orders)
108            .support_contingent_orders(self.support_contingent_orders)
109            .use_position_ids(self.use_position_ids)
110            .use_random_ids(self.use_random_ids)
111            .use_reduce_only(self.use_reduce_only)
112            .build()
113    }
114}
115
116impl Default for SandboxExecutionClientConfig {
117    fn default() -> Self {
118        Self::builder().build()
119    }
120}