Skip to main content

ctrader_rs/
account.rs

1///
2///
3///
4///
5///
6///
7///
8///
9///
10///
11///
12///
13///
14use crate::payload;
15use crate::proto::common::*;
16use crate::{client::Client, error::Error};
17
18impl Client {
19    /// Log out a trader account (does not disconnect the TCP session).
20    ///
21    ///
22    ///
23    ///
24    ///
25    ///
26    ///
27    ///
28    ///
29    ///
30    ///
31    pub async fn account_logout(
32        &self,
33        ctid_trader_account_id: i64,
34    ) -> Result<ProtoOaAccountLogoutRes, Error> {
35        let req = ProtoOaAccountLogoutReq {
36            payload_type: Some(payload::OA_ACCOUNT_LOGOUT_REQ as i32),
37            ctid_trader_account_id,
38        };
39        self.command(
40            payload::OA_ACCOUNT_LOGOUT_REQ,
41            req,
42            payload::OA_ACCOUNT_LOGOUT_RES,
43        )
44        .await
45    }
46
47    /// Return all trader accounts linked to the given OAuth access token.
48    ///
49    ///
50    ///
51    ///
52    ///
53    ///
54    ///
55    ///
56    ///
57    /// Mirrors `ProtoOAGetAccountListByAccessTokenReq`.
58    pub async fn get_accounts_by_access_token(
59        &self,
60        access_token: &str,
61    ) -> Result<ProtoOaGetAccountListByAccessTokenRes, Error> {
62        let req = ProtoOaGetAccountListByAccessTokenReq {
63            payload_type: Some(payload::OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_REQ as i32),
64            access_token: access_token.to_string(),
65        };
66        self.command(
67            payload::OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_REQ,
68            req,
69            payload::OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_RES,
70        )
71        .await
72    }
73
74    /// Get full trader/account info (balance, leverage, currency, etc.).
75    ///
76    ///
77    ///
78    ///
79    ///
80    ///
81    ///
82    ///
83    ///
84    pub async fn get_trader(&self, ctid_trader_account_id: i64) -> Result<ProtoOaTraderRes, Error> {
85        let req = ProtoOaTraderReq {
86            payload_type: Some(payload::OA_TRADER_REQ as i32),
87            ctid_trader_account_id,
88        };
89        self.command(payload::OA_TRADER_REQ, req, payload::OA_TRADER_RES)
90            .await
91    }
92}
93
94#[cfg(test)]
95mod tests {
96
97    #[async_std::test]
98    async fn test() {}
99}