finlight_client/config.rs
1use std::time::Duration;
2
3/// Default REST endpoint.
4pub const DEFAULT_BASE_URL: &str = "https://api.finlight.me";
5/// Default WebSocket endpoint.
6pub const DEFAULT_WSS_URL: &str = "wss://wss.finlight.me";
7/// Default per-request timeout.
8pub const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5);
9/// Default total request attempts.
10pub const DEFAULT_RETRY_COUNT: u32 = 3;
11
12/// Configures the finlight client. Only `api_key` is required; the remaining
13/// fields default to the documented values shared by all sibling clients.
14#[derive(Clone, Debug)]
15pub struct Config {
16 /// Your finlight API key (required).
17 pub api_key: String,
18 /// REST endpoint, default `https://api.finlight.me`.
19 pub base_url: String,
20 /// WebSocket endpoint, default `wss://wss.finlight.me`.
21 pub wss_url: String,
22 /// Per-request timeout (also the WebSocket dial timeout), default 5s.
23 pub timeout: Duration,
24 /// Total request attempts (initial try + retries), default 3.
25 pub retry_count: u32,
26}
27
28impl Config {
29 /// Returns a config with the given API key and default endpoints,
30 /// timeout, and retry count.
31 pub fn new(api_key: impl Into<String>) -> Self {
32 Self {
33 api_key: api_key.into(),
34 base_url: DEFAULT_BASE_URL.to_owned(),
35 wss_url: DEFAULT_WSS_URL.to_owned(),
36 timeout: DEFAULT_TIMEOUT,
37 retry_count: DEFAULT_RETRY_COUNT,
38 }
39 }
40}