get_position_unrealized_pnl/
get_position_unrealized_pnl.rs1use ctrader_rs::{Client, Config};
7use std::time::Duration;
8
9#[tokio::main]
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11 dotenvy::dotenv().ok();
12
13 tracing_subscriber::fmt()
14 .with_env_filter("new_order=debug,ctrader_rs=debug")
15 .with_line_number(true)
16 .init();
17
18 let client_id = std::env::var("CTRADER_CLIENT_ID")?;
19 let secret = std::env::var("CTRADER_SECRET")?;
20 let account_id: i64 = std::env::var("CTRADER_ACCOUNT_ID")?.parse()?;
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 let res = client.position_unrealized_pnl(account_id).await?;
29
30 tracing::info!("Position Unrealized PnL: {:?}", res);
31
32 Ok(())
33}