Skip to main content

nautilus_coinbase/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 Coinbase configuration.
17
18use nautilus_model::enums::AccountType;
19use pyo3::pymethods;
20use rust_decimal::Decimal;
21
22use crate::{
23    common::enums::{CoinbaseEnvironment, CoinbaseMarginType},
24    config::{CoinbaseDataClientConfig, CoinbaseExecClientConfig},
25};
26
27#[pymethods]
28#[pyo3_stub_gen::derive::gen_stub_pymethods]
29impl CoinbaseDataClientConfig {
30    /// Configuration for the Coinbase live data client.
31    #[new]
32    #[pyo3(signature = (
33        api_key = None,
34        api_secret = None,
35        base_url_rest = None,
36        base_url_ws = None,
37        proxy_url = None,
38        environment = None,
39        http_timeout_secs = None,
40        ws_timeout_secs = None,
41        update_instruments_interval_mins = None,
42        derivatives_poll_interval_secs = None,
43    ))]
44    #[expect(clippy::too_many_arguments)]
45    fn py_new(
46        api_key: Option<String>,
47        api_secret: Option<String>,
48        base_url_rest: Option<String>,
49        base_url_ws: Option<String>,
50        proxy_url: Option<String>,
51        environment: Option<CoinbaseEnvironment>,
52        http_timeout_secs: Option<u64>,
53        ws_timeout_secs: Option<u64>,
54        update_instruments_interval_mins: Option<u64>,
55        derivatives_poll_interval_secs: Option<u64>,
56    ) -> Self {
57        let defaults = Self::default();
58        Self {
59            api_key,
60            api_secret,
61            base_url_rest,
62            base_url_ws,
63            proxy_url,
64            environment: environment.unwrap_or(defaults.environment),
65            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
66            ws_timeout_secs: ws_timeout_secs.unwrap_or(defaults.ws_timeout_secs),
67            update_instruments_interval_mins: update_instruments_interval_mins
68                .unwrap_or(defaults.update_instruments_interval_mins),
69            derivatives_poll_interval_secs: derivatives_poll_interval_secs
70                .unwrap_or(defaults.derivatives_poll_interval_secs),
71            transport_backend: defaults.transport_backend,
72        }
73    }
74
75    /// Returns the optional proxy URL for HTTP and WebSocket transports.
76    #[getter]
77    fn proxy_url(&self) -> Option<String> {
78        self.proxy_url.clone()
79    }
80
81    fn __repr__(&self) -> String {
82        format!("{self:?}")
83    }
84}
85
86#[pymethods]
87#[pyo3_stub_gen::derive::gen_stub_pymethods]
88impl CoinbaseExecClientConfig {
89    /// Configuration for the Coinbase live execution client.
90    #[new]
91    #[pyo3(signature = (
92        api_key = None,
93        api_secret = None,
94        base_url_rest = None,
95        base_url_ws = None,
96        proxy_url = None,
97        environment = None,
98        http_timeout_secs = None,
99        max_retries = None,
100        retry_delay_initial_ms = None,
101        retry_delay_max_ms = None,
102        account_type = None,
103        default_margin_type = None,
104        default_leverage = None,
105        retail_portfolio_id = None,
106    ))]
107    #[expect(clippy::too_many_arguments)]
108    fn py_new(
109        api_key: Option<String>,
110        api_secret: Option<String>,
111        base_url_rest: Option<String>,
112        base_url_ws: Option<String>,
113        proxy_url: Option<String>,
114        environment: Option<CoinbaseEnvironment>,
115        http_timeout_secs: Option<u64>,
116        max_retries: Option<u32>,
117        retry_delay_initial_ms: Option<u64>,
118        retry_delay_max_ms: Option<u64>,
119        account_type: Option<AccountType>,
120        default_margin_type: Option<CoinbaseMarginType>,
121        default_leverage: Option<Decimal>,
122        retail_portfolio_id: Option<String>,
123    ) -> Self {
124        let defaults = Self::default();
125        Self {
126            api_key,
127            api_secret,
128            base_url_rest,
129            base_url_ws,
130            proxy_url,
131            environment: environment.unwrap_or(defaults.environment),
132            http_timeout_secs: http_timeout_secs.unwrap_or(defaults.http_timeout_secs),
133            max_retries: max_retries.unwrap_or(defaults.max_retries),
134            retry_delay_initial_ms: retry_delay_initial_ms
135                .unwrap_or(defaults.retry_delay_initial_ms),
136            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(defaults.retry_delay_max_ms),
137            account_type: account_type.unwrap_or(defaults.account_type),
138            default_margin_type,
139            default_leverage,
140            retail_portfolio_id,
141            transport_backend: defaults.transport_backend,
142        }
143    }
144
145    /// Returns the optional proxy URL for HTTP and WebSocket transports.
146    #[getter]
147    fn proxy_url(&self) -> Option<String> {
148        self.proxy_url.clone()
149    }
150
151    fn __repr__(&self) -> String {
152        format!("{self:?}")
153    }
154}