Skip to main content

ctrader_rs/
margin.rs

1///
2///
3///
4///
5///
6///
7///
8///
9///
10///
11///
12///
13///
14use crate::{client::Client, error::Error, payload, proto::common::*};
15
16impl Client {
17    /// Get active margin calls for the account.
18    ///
19    ///
20    ///
21    ///
22    ///
23    ///
24    ///
25    ///
26    ///
27    ///
28    ///
29    pub async fn get_margin_call_list(
30        &self,
31        ctid_trader_account_id: i64,
32    ) -> Result<ProtoOaMarginCallListRes, Error> {
33        let req = ProtoOaMarginCallListReq {
34            payload_type: Some(payload::OA_MARGIN_CALL_LIST_REQ as i32),
35            ctid_trader_account_id,
36        };
37        self.command(
38            payload::OA_MARGIN_CALL_LIST_REQ,
39            req,
40            payload::OA_MARGIN_CALL_LIST_RES,
41        )
42        .await
43    }
44
45    /// Calculate expected margin for a list of volumes on a symbol.
46    ///
47    ///
48    ///
49    ///
50    ///
51    ///
52    ///
53    ///
54    ///
55    ///
56    ///
57    ///
58    /// Useful for pre-trade checks before placing an order.
59    /// Note: `moneyDigits` in the response specifies the monetary scale factor.
60    pub async fn get_expected_margin(
61        &self,
62        ctid_trader_account_id: i64,
63        symbol_id: i64,
64        volume: Vec<i64>,
65    ) -> Result<ProtoOaExpectedMarginRes, Error> {
66        let req = ProtoOaExpectedMarginReq {
67            payload_type: Some(payload::OA_EXPECTED_MARGIN_REQ as i32),
68            ctid_trader_account_id,
69            symbol_id,
70            volume,
71        };
72        self.command(
73            payload::OA_EXPECTED_MARGIN_REQ,
74            req,
75            payload::OA_EXPECTED_MARGIN_RES,
76        )
77        .await
78    }
79}
80
81#[cfg(test)]
82mod tests {
83
84    #[async_std::test]
85    async fn test() {}
86}