//! Open a new BUY order.
//!
//! Usage:
//!   cargo run --example get_trader

use ctrader_rs::{Client, Config};
use std::time::Duration;

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

    tracing_subscriber::fmt()
        .with_env_filter("new_order=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: i64 = std::env::var("CTRADER_ACCOUNT_ID")?.parse()?;

    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");

    let res = client.get_trader(account_id).await?;

    tracing::info!("Trader: {:?}", res);

    Ok(())
}
