Skip to main content

version/
version.rs

1//! Get all broker account IDs linked to your access token.
2//!
3//! Usage:
4//!   cargo run --example version
5
6use std::time::Duration;
7
8use ctrader_rs::{Client, Config};
9
10#[tokio::main]
11async fn main() -> Result<(), Box<dyn std::error::Error>> {
12    dotenvy::dotenv().ok();
13
14    tracing_subscriber::fmt()
15        .with_env_filter("version=debug,ctrader_rs=debug")
16        .with_line_number(true)
17        .init();
18
19    let client_id = std::env::var("CTRADER_CLIENT_ID")?;
20    let secret = std::env::var("CTRADER_SECRET")?;
21
22    let config = Config::new(client_id, secret).deadline(Duration::from_secs(5));
23
24    tracing::debug!("Connecting to demo.ctraderapi.com:5035 …");
25    let client = Client::start(config).await?;
26    tracing::debug!("✓ Connected and application authenticated");
27
28    // Fetch all accounts linked to the token
29    let res = client.version().await?;
30
31    tracing::debug!("Version: {}", res.version);
32
33    Ok(())
34}