Skip to main content

flowsurface_data/config/
network.rs

1use serde::{Deserialize, Serialize};
2
3/// Combined network configuration.
4///
5/// Both settings take effect after a restart of the application.
6#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
7pub struct Network {
8    pub proxy: Option<exchange::proxy::Proxy>,
9    pub server_url: Option<String>,
10    /// Bearer token for the market-data server.
11    /// Stored in the system keychain, never persisted to JSON.
12    #[serde(skip)]
13    pub server_auth_token: Option<String>,
14    pub trade_fetch_mode: TradeFetchMode,
15}
16
17impl Network {
18    /// Return a copy suitable for disk persistence (proxy auth stripped).
19    /// Auth credentials are stored separately in the system keychain.
20    pub fn for_persistence(&self) -> Self {
21        Self {
22            proxy: self.proxy.clone().map(|p| p.without_auth()),
23            ..self.clone()
24        }
25    }
26}
27
28#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(tag = "type")]
30pub enum TradeFetchMode {
31    #[default]
32    Off,
33    /// Direct exchange API only (Binance spot/linear/inverse).
34    Exchange,
35    /// Remote Arrow IPC market-data server.
36    Server,
37}
38
39impl std::fmt::Display for TradeFetchMode {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        match self {
42            Self::Off => write!(f, "Off"),
43            Self::Exchange => write!(f, "Exchange"),
44            Self::Server => write!(f, "Server"),
45        }
46    }
47}