//! Get all broker account IDs linked to your access token.
//!
//! Usage:
//!   cargo run --example subscribe

use std::time::Duration;

use ctrader_rs::{Client, Config};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    dotenvy::dotenv().ok();

    tracing_subscriber::fmt()
        .with_env_filter("get_accounts=debug,ctrader_rs=debug")
        .with_line_number(true)
        .init();

    let client_id = std::env::var("CTRADER_CLIENT_ID")?;
    let secret = std::env::var("CTRADER_SECRET")?;
    let account_id = std::env::var("CTRADER_ACCOUNT_ID")?.parse::<i64>()?;

    let config = Config::new(client_id, secret).deadline(Duration::from_secs(5));

    tracing::debug!("Connecting to demo.ctraderapi.com:5035 …");
    let client = Client::start(config).await?;
    tracing::debug!("✓ Connected and application authenticated");

    // Fetch all accounts linked to the token
    let res = client.subscribe_symbol(vec![61], account_id).await?;

    println!("{:?}", res);

    Ok(())
}
