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