Skip to main content

nautilus_polymarket/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
16use nautilus_model::identifiers::{AccountId, TraderId};
17use pyo3::pymethods;
18
19use crate::{
20    common::enums::SignatureType,
21    config::{PolymarketDataClientConfig, PolymarketExecClientConfig},
22};
23
24#[pymethods]
25#[pyo3_stub_gen::derive::gen_stub_pymethods]
26impl PolymarketDataClientConfig {
27    /// Configuration for the Polymarket data client.
28    #[new]
29    #[pyo3(signature = (base_url_http=None, base_url_ws=None, base_url_gamma=None, base_url_data_api=None, http_timeout_secs=None, ws_timeout_secs=None, ws_max_subscriptions=None, update_instruments_interval_mins=None, subscribe_new_markets=None, auto_load_missing_instruments=None, auto_load_debounce_ms=None))]
30    #[expect(clippy::too_many_arguments)]
31    fn py_new(
32        base_url_http: Option<String>,
33        base_url_ws: Option<String>,
34        base_url_gamma: Option<String>,
35        base_url_data_api: Option<String>,
36        http_timeout_secs: Option<u64>,
37        ws_timeout_secs: Option<u64>,
38        ws_max_subscriptions: Option<usize>,
39        update_instruments_interval_mins: Option<u64>,
40        subscribe_new_markets: Option<bool>,
41        auto_load_missing_instruments: Option<bool>,
42        auto_load_debounce_ms: Option<u64>,
43    ) -> Self {
44        let default = Self::default();
45        Self {
46            base_url_http,
47            base_url_ws,
48            base_url_gamma,
49            base_url_data_api,
50            http_timeout_secs: http_timeout_secs.unwrap_or(default.http_timeout_secs),
51            ws_timeout_secs: ws_timeout_secs.unwrap_or(default.ws_timeout_secs),
52            ws_max_subscriptions: ws_max_subscriptions.unwrap_or(default.ws_max_subscriptions),
53            update_instruments_interval_mins: update_instruments_interval_mins
54                .unwrap_or(default.update_instruments_interval_mins),
55            subscribe_new_markets: subscribe_new_markets.unwrap_or(false),
56            auto_load_missing_instruments: auto_load_missing_instruments
57                .unwrap_or(default.auto_load_missing_instruments),
58            auto_load_debounce_ms: auto_load_debounce_ms.unwrap_or(default.auto_load_debounce_ms),
59            filters: Vec::new(),
60            new_market_filter: None,
61            transport_backend: default.transport_backend,
62        }
63    }
64
65    fn __repr__(&self) -> String {
66        format!("{self:?}")
67    }
68
69    fn __str__(&self) -> String {
70        format!("{self:?}")
71    }
72}
73
74#[pymethods]
75#[pyo3_stub_gen::derive::gen_stub_pymethods]
76impl PolymarketExecClientConfig {
77    /// Configuration for the Polymarket execution client.
78    #[new]
79    #[expect(clippy::too_many_arguments)]
80    #[pyo3(signature = (trader_id=None, account_id=None, private_key=None, api_key=None, api_secret=None, passphrase=None, funder=None, signature_type=None, base_url_http=None, base_url_ws=None, base_url_data_api=None, http_timeout_secs=None, max_retries=None, retry_delay_initial_ms=None, retry_delay_max_ms=None, ack_timeout_secs=None))]
81    fn py_new(
82        trader_id: Option<String>,
83        account_id: Option<String>,
84        private_key: Option<String>,
85        api_key: Option<String>,
86        api_secret: Option<String>,
87        passphrase: Option<String>,
88        funder: Option<String>,
89        signature_type: Option<SignatureType>,
90        base_url_http: Option<String>,
91        base_url_ws: Option<String>,
92        base_url_data_api: Option<String>,
93        http_timeout_secs: Option<u64>,
94        max_retries: Option<u32>,
95        retry_delay_initial_ms: Option<u64>,
96        retry_delay_max_ms: Option<u64>,
97        ack_timeout_secs: Option<u64>,
98    ) -> Self {
99        let default = Self::default();
100        Self {
101            trader_id: trader_id.map_or(default.trader_id, |s| TraderId::from(s.as_str())),
102            account_id: account_id.map_or(default.account_id, |s| AccountId::from(s.as_str())),
103            private_key,
104            api_key,
105            api_secret,
106            passphrase,
107            funder,
108            signature_type: signature_type.unwrap_or(default.signature_type),
109            base_url_http,
110            base_url_ws,
111            base_url_data_api,
112            http_timeout_secs: http_timeout_secs.unwrap_or(default.http_timeout_secs),
113            max_retries: max_retries.unwrap_or(default.max_retries),
114            retry_delay_initial_ms: retry_delay_initial_ms
115                .unwrap_or(default.retry_delay_initial_ms),
116            retry_delay_max_ms: retry_delay_max_ms.unwrap_or(default.retry_delay_max_ms),
117            ack_timeout_secs: ack_timeout_secs.unwrap_or(default.ack_timeout_secs),
118            transport_backend: default.transport_backend,
119        }
120    }
121
122    fn __repr__(&self) -> String {
123        format!("{self:?}")
124    }
125
126    fn __str__(&self) -> String {
127        format!("{self:?}")
128    }
129}