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