Skip to main content

limitless/
config.rs

1use std::borrow::Cow;
2
3/// Configuration for the Limitless Exchange API client.
4///
5/// Controls the REST API endpoint, WebSocket endpoint, and receive window
6/// for HMAC-signed request validation.
7#[derive(Clone, Debug)]
8pub struct Config {
9    /// Base URL for REST API requests.
10    pub rest_api_endpoint: Cow<'static, str>,
11    /// WebSocket endpoint for real-time streams.
12    pub ws_endpoint: Cow<'static, str>,
13    /// Maximum permissible age of a request in milliseconds (default: 5000).
14    pub recv_window: u64,
15}
16
17impl Config {
18    /// Default mainnet REST API endpoint.
19    pub const DEFAULT_REST_API_ENDPOINT: &str = "https://api.limitless.exchange";
20    /// Default mainnet WebSocket endpoint.
21    pub const DEFAULT_WS_ENDPOINT: &str = "wss://ws.limitless.exchange/markets";
22
23    /// Create a new `Config` with custom endpoints and receive window.
24    ///
25    /// Use this when you need to point to a staging environment or adjust
26    /// the timing tolerance for signed requests.
27    pub fn new(
28        rest_api_endpoint: impl AsRef<str>,
29        ws_endpoint: impl AsRef<str>,
30        recv_window: impl Into<u64>,
31    ) -> Self {
32        Self {
33            rest_api_endpoint: Cow::Owned(rest_api_endpoint.as_ref().to_string()),
34            ws_endpoint: Cow::Owned(ws_endpoint.as_ref().to_string()),
35            recv_window: recv_window.into(),
36        }
37    }
38
39    /// Returns the default mainnet configuration.
40    ///
41    /// REST: `https://api.limitless.exchange`
42    /// WS:   `wss://ws.limitless.exchange/markets`
43    /// Recv window: 5000 ms
44    pub const fn default() -> Self {
45        Self {
46            rest_api_endpoint: Cow::Borrowed(Self::DEFAULT_REST_API_ENDPOINT),
47            ws_endpoint: Cow::Borrowed(Self::DEFAULT_WS_ENDPOINT),
48            recv_window: 5000,
49        }
50    }
51
52    /// Set a custom receive window (in milliseconds).
53    ///
54    /// The receive window controls how far from server time a request timestamp
55    /// may deviate before being rejected.
56    pub fn set_recv_window(self, recv_window: u64) -> Self {
57        Self {
58            recv_window,
59            ..self
60        }
61    }
62}