ctrader-rs 0.1.2

Rust SDK for the cTrader Open API
Documentation
///
///
///
///
///
///
///
///
///
///
///
///
///
use crate::payload;
use crate::proto::common::*;
use crate::{client::Client, error::Error};

impl Client {
    /// Log out a trader account (does not disconnect the TCP session).
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    pub async fn account_logout(
        &self,
        ctid_trader_account_id: i64,
    ) -> Result<ProtoOaAccountLogoutRes, Error> {
        let req = ProtoOaAccountLogoutReq {
            payload_type: Some(payload::OA_ACCOUNT_LOGOUT_REQ as i32),
            ctid_trader_account_id,
        };
        self.command(
            payload::OA_ACCOUNT_LOGOUT_REQ,
            req,
            payload::OA_ACCOUNT_LOGOUT_RES,
        )
        .await
    }

    /// Return all trader accounts linked to the given OAuth access token.
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    /// Mirrors `ProtoOAGetAccountListByAccessTokenReq`.
    pub async fn get_accounts_by_access_token(
        &self,
        access_token: &str,
    ) -> Result<ProtoOaGetAccountListByAccessTokenRes, Error> {
        let req = ProtoOaGetAccountListByAccessTokenReq {
            payload_type: Some(payload::OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_REQ as i32),
            access_token: access_token.to_string(),
        };
        self.command(
            payload::OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_REQ,
            req,
            payload::OA_GET_ACCOUNTS_BY_ACCESS_TOKEN_RES,
        )
        .await
    }

    /// Get full trader/account info (balance, leverage, currency, etc.).
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    pub async fn get_trader(&self, ctid_trader_account_id: i64) -> Result<ProtoOaTraderRes, Error> {
        let req = ProtoOaTraderReq {
            payload_type: Some(payload::OA_TRADER_REQ as i32),
            ctid_trader_account_id,
        };
        self.command(payload::OA_TRADER_REQ, req, payload::OA_TRADER_RES)
            .await
    }
}

#[cfg(test)]
mod tests {

    #[async_std::test]
    async fn test() {}
}