Skip to main content

ctrader_rs/
deal.rs

1///
2///
3///
4///
5///
6///
7///
8///
9///
10///
11///
12///
13use crate::{client::Client, error::Error, payload, proto::common::*};
14
15impl Client {
16    /// List deals (filled order history) filtered by time range.
17    ///
18    ///
19    ///
20    ///
21    ///
22    ///
23    ///
24    ///
25    ///
26    ///
27    ///
28    ///
29    /// Timestamps are Unix milliseconds.  `max_rows` caps the result set.
30    pub async fn deal_list(
31        &self,
32        ctid_trader_account_id: i64,
33        from_timestamp: i64,
34        to_timestamp: i64,
35        max_rows: Option<i32>,
36    ) -> Result<ProtoOaDealListRes, Error> {
37        let req = ProtoOaDealListReq {
38            payload_type: Some(payload::OA_DEAL_LIST_REQ as i32),
39            ctid_trader_account_id,
40            from_timestamp: Some(from_timestamp),
41            to_timestamp: Some(to_timestamp),
42            max_rows,
43        };
44        self.command(payload::OA_DEAL_LIST_REQ, req, payload::OA_DEAL_LIST_RES)
45            .await
46    }
47
48    /// List deals associated with a specific position.
49    ///
50    ///
51    ///
52    ///
53    ///
54    ///
55    ///
56    ///
57    ///
58    ///
59    ///
60    ///
61    ///
62    ///
63    ///
64    pub async fn deal_list_by_position(
65        &self,
66        ctid_trader_account_id: i64,
67        position_id: i64,
68        from_timestamp: Option<i64>,
69        to_timestamp: Option<i64>,
70    ) -> Result<ProtoOaDealListByPositionIdRes, Error> {
71        let req = ProtoOaDealListByPositionIdReq {
72            payload_type: Some(payload::OA_DEAL_LIST_BY_POSITION_ID_REQ as i32),
73            ctid_trader_account_id,
74            position_id,
75            from_timestamp,
76            to_timestamp,
77        };
78
79        self.command(
80            payload::OA_DEAL_LIST_BY_POSITION_ID_REQ,
81            req,
82            payload::OA_DEAL_LIST_BY_POSITION_ID_RES,
83        )
84        .await
85    }
86
87    ///
88    ///
89    ///
90    ///
91    ///
92    ///
93    ///
94    ///
95    pub async fn deal_offset_list(
96        &self,
97        ctid_trader_account_id: i64,
98        deal_id: i64,
99    ) -> Result<ProtoOaDealOffsetListRes, Error> {
100        let req = ProtoOaDealOffsetListReq {
101            deal_id,
102            ctid_trader_account_id,
103            payload_type: Some(payload::OA_DEAL_OFFSET_LIST_REQ as i32),
104            ..Default::default()
105        };
106
107        self.command(
108            payload::OA_DEAL_OFFSET_LIST_REQ,
109            req,
110            payload::OA_DEAL_OFFSET_LIST_RES,
111        )
112        .await
113    }
114}
115
116#[cfg(test)]
117mod tests {
118
119    #[async_std::test]
120    async fn test() {}
121}