Skip to main content

Module margin

Module margin 

Source
Expand description

Margin of positions and margin calls of an account.

The server reports by itself when the margin a position uses changes, when a margin call of an account is changed and when one is triggered; nothing is subscribed to.

use ctrader_connector::common::config::ConfigurationOpenApi;
use ctrader_connector::open_api::client::OpenApiClient;
use ctrader_connector::open_api::margin::MarginEvent;

let client = OpenApiClient::connect(ConfigurationOpenApi::from_env()?).await?;
client.authorise_application().await?;
let account = client.accounts().await?[0].id;
client.authorise_account(account).await?;
for call in client.margin_calls(account).await? {
    println!("{:?} at {}", call.level, call.threshold);
}
let mut margin = client.margin_events(account);
loop {
    if let MarginEvent::Changed(change) = margin.next().await? {
        println!("{} uses {}", change.position, change.used_margin);
    }
}

Structs§

MarginCall
Margin call of an account: the margin level at which the account is notified.
MarginChange
Change of the margin a position uses.
MarginStream
Margin events of one account, in the order the server sent them.

Enums§

MarginCallLevel
Which of the margin calls of an account one is.
MarginEvent
One event about the margin of an account.