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