Skip to main content

ccxt_core/
config.rs

1//! Configuration types for exchanges.
2
3use std::time::Duration;
4
5/// Retry policy for HTTP requests.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct RetryPolicy {
8    /// Maximum number of retries.
9    pub max_retries: u32,
10    /// Delay between retries.
11    pub delay: Duration,
12}
13
14impl Default for RetryPolicy {
15    fn default() -> Self {
16        Self {
17            max_retries: 3,
18            delay: Duration::from_millis(1000),
19        }
20    }
21}
22
23/// Proxy configuration.
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct ProxyConfig {
26    /// Proxy URL (e.g., "http://127.0.0.1:8080").
27    pub url: String,
28    /// Optional username for authentication.
29    pub username: Option<String>,
30    /// Optional password for authentication.
31    pub password: Option<String>,
32}
33
34impl ProxyConfig {
35    /// Create a new proxy configuration with just a URL.
36    pub fn new(url: impl Into<String>) -> Self {
37        Self {
38            url: url.into(),
39            username: None,
40            password: None,
41        }
42    }
43
44    /// Set credentials for the proxy.
45    pub fn with_credentials(
46        mut self,
47        username: impl Into<String>,
48        password: impl Into<String>,
49    ) -> Self {
50        self.username = Some(username.into());
51        self.password = Some(password.into());
52        self
53    }
54}