1use ctrader_rs::{proto::common::ProtoOaTradeSide, 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 token = std::env::var("CTRADER_TOKEN")?;
21 let account_id: i64 = std::env::var("CTRADER_ACCOUNT_ID")?.parse()?;
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 let auth_res = client.account_auth(account_id, &token).await?;
31 assert_eq!(auth_res.ctid_trader_account_id, account_id);
32 tracing::debug!("✓ Account {account_id} authenticated");
33
34 let res = client
35 .new_market_order(account_id, 41, ProtoOaTradeSide::Buy, 100000)
36 .await?;
37
38 tracing::debug!("{:?}", res);
39
40 loop {}
59}