Files
foxhunt/crates/ctrader-openapi/src/config.rs
jgrusewski 9c3d741a08 refactor: restructure repo — crates/, bin/, testing/ layout
Move 17 library crates into crates/, CLI binary into bin/fxt,
consolidate 10 test crates into testing/, split config crate
from deployment config files.

Root directory reduced from 38+ to ~17 directories.
All Cargo.toml paths and build.rs proto refs updated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 11:56:00 +01:00

77 lines
1.9 KiB
Rust

//! cTrader Open API configuration.
use serde::{Deserialize, Serialize};
/// Target environment (demo vs. live).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CTraderEnvironment {
/// `demo.ctraderapi.com:5035`
Demo,
/// `live.ctraderapi.com:5035`
Live,
}
impl CTraderEnvironment {
/// TCP host for the environment.
pub const fn host(&self) -> &'static str {
match self {
Self::Demo => "demo.ctraderapi.com",
Self::Live => "live.ctraderapi.com",
}
}
/// TCP port (both envs use 5035).
pub const fn port(&self) -> u16 {
5035
}
}
impl Default for CTraderEnvironment {
fn default() -> Self {
Self::Demo
}
}
/// Configuration for a cTrader Open API connection.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CTraderConfig {
/// OAuth2 application client ID.
pub client_id: String,
/// OAuth2 application client secret.
pub client_secret: String,
/// OAuth2 access token (obtained via auth code or refresh flow).
pub access_token: String,
/// cTID trader account ID.
pub account_id: i64,
/// Demo or Live environment.
#[serde(default)]
pub environment: CTraderEnvironment,
/// Heartbeat interval in seconds (cTrader requires ≤ 10s).
#[serde(default = "default_heartbeat_interval")]
pub heartbeat_interval_secs: u64,
/// Per-request timeout in milliseconds.
#[serde(default = "default_request_timeout")]
pub request_timeout_ms: u64,
/// Maximum reconnection attempts before giving up.
#[serde(default = "default_max_reconnect")]
pub max_reconnect_attempts: u32,
}
const fn default_heartbeat_interval() -> u64 {
10
}
const fn default_request_timeout() -> u64 {
5000
}
const fn default_max_reconnect() -> u32 {
5
}