Skip to main content

nautilus_dydx/python/
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//! Python bindings for dYdX configuration.
17
18use nautilus_core::string::secret::SecretString;
19use nautilus_model::identifiers::AccountId;
20use pyo3::prelude::*;
21
22use crate::{
23    common::enums::DydxNetwork,
24    config::{DydxDataClientConfig, DydxExecutionClientConfig},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl DydxDataClientConfig {
30    /// Configuration for the dYdX data client.
31    #[new]
32    #[pyo3(signature = (proxy_url=None, network=None))]
33    fn py_new(proxy_url: Option<String>, network: Option<DydxNetwork>) -> Self {
34        Self {
35            network: network.unwrap_or_default(),
36            proxy_url: proxy_url.map(SecretString::from),
37            ..Self::default()
38        }
39    }
40
41    #[getter]
42    const fn has_proxy_url(&self) -> bool {
43        self.proxy_url.is_some()
44    }
45
46    fn __repr__(&self) -> String {
47        stringify!(DydxDataClientConfig).to_string()
48    }
49}
50
51#[pymethods]
52#[pyo3_stub_gen::derive::gen_stub_pymethods]
53impl DydxExecutionClientConfig {
54    /// Configuration for the dYdX execution client.
55    #[new]
56    #[pyo3(signature = (
57        account_id,
58        proxy_url=None,
59        network=None,
60        private_key=None,
61        wallet_address=None,
62        subaccount_number=0,
63    ))]
64    fn py_new(
65        account_id: AccountId,
66        proxy_url: Option<String>,
67        network: Option<DydxNetwork>,
68        private_key: Option<String>,
69        wallet_address: Option<String>,
70        subaccount_number: u32,
71    ) -> Self {
72        Self {
73            account_id,
74            network: network.unwrap_or_default(),
75            private_key: private_key.map(SecretString::from),
76            wallet_address,
77            subaccount_number,
78            proxy_url: proxy_url.map(SecretString::from),
79            ..Self::default()
80        }
81    }
82
83    #[getter]
84    const fn has_proxy_url(&self) -> bool {
85        self.proxy_url.is_some()
86    }
87
88    fn __repr__(&self) -> String {
89        stringify!(DydxExecutionClientConfig).to_string()
90    }
91}