Skip to main content

subscribe/
subscribe.rs

1//! Get all broker account IDs linked to your access token.
2//!
3//! Usage:
4//!   cargo run --example subscribe
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("get_accounts=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    let account_id = std::env::var("CTRADER_ACCOUNT_ID")?.parse::<i64>()?;
22
23    let config = Config::new(client_id, secret).deadline(Duration::from_secs(5));
24
25    tracing::debug!("Connecting to demo.ctraderapi.com:5035 …");
26    let client = Client::start(config).await?;
27    tracing::debug!("✓ Connected and application authenticated");
28
29    // Fetch all accounts linked to the token
30    let res = client.subscribe_symbol(vec![61], account_id).await?;
31
32    println!("{:?}", res);
33
34    Ok(())
35}