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, TraderId};
19use pyo3::prelude::*;
20
21use crate::{
22    common::enums::DydxNetwork,
23    config::{DydxDataClientConfig, DydxExecClientConfig},
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    fn __repr__(&self) -> String {
41        format!("{self:?}")
42    }
43}
44
45#[pymethods]
46#[pyo3_stub_gen::derive::gen_stub_pymethods]
47impl DydxExecClientConfig {
48    /// Configuration for the dYdX execution client.
49    #[new]
50    #[pyo3(signature = (
51        trader_id,
52        account_id,
53        proxy_url=None,
54        network=None,
55        private_key=None,
56        wallet_address=None,
57        subaccount_number=0,
58    ))]
59    fn py_new(
60        trader_id: TraderId,
61        account_id: AccountId,
62        proxy_url: Option<String>,
63        network: Option<DydxNetwork>,
64        private_key: Option<String>,
65        wallet_address: Option<String>,
66        subaccount_number: u32,
67    ) -> Self {
68        Self {
69            trader_id,
70            account_id,
71            network: network.unwrap_or_default(),
72            private_key,
73            wallet_address,
74            subaccount_number,
75            proxy_url,
76            ..Self::default()
77        }
78    }
79
80    fn __repr__(&self) -> String {
81        format!("{self:?}")
82    }
83}