1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
use crate::{client::Client, error::Error, payload, proto::common::*};
impl Client {
/// Close an open position, either fully or partially.
///
///
///
///
///
///
///
///
///
///
///
///
/// To close fully, pass the full position volume.
pub async fn close_position(
&self,
ctid_trader_account_id: i64,
position_id: i64,
volume: i64,
) -> Result<ProtoOaExecutionEvent, Error> {
let req = ProtoOaClosePositionReq {
payload_type: Some(payload::OA_CLOSE_POSITION_REQ as i32),
ctid_trader_account_id,
position_id,
volume,
};
self.command(
payload::OA_CLOSE_POSITION_REQ,
req,
payload::OA_EXECUTION_EVENT,
)
.await
}
/// Amend the Stop Loss and/or Take Profit of an open position.
///
///
///
///
///
///
///
///
///
///
///
///
/// `stop_loss` and `take_profit` are absolute price levels.
pub async fn amend_position_sltp(
&self,
ctid_trader_account_id: i64,
position_id: i64,
stop_loss: Option<f64>,
take_profit: Option<f64>,
trailing_stop_loss: Option<bool>,
) -> Result<ProtoOaExecutionEvent, Error> {
let req = ProtoOaAmendPositionSltpReq {
payload_type: Some(ProtoOaPayloadType::ProtoOaAmendPositionSltpReq as i32),
ctid_trader_account_id,
position_id,
stop_loss,
take_profit,
trailing_stop_loss,
..Default::default()
};
self.command(
payload::OA_AMEND_POSITION_SLTP_REQ,
req,
payload::OA_EXECUTION_EVENT,
)
.await
}
/// Get unrealized P&L for all open positions.
///
///
///
///
///
///
///
///
///
///
///
///
///
/// Note: monetary values in the response are scaled by `10^moneyDigits`.
pub async fn position_unrealized_pnl(
&self,
ctid_trader_account_id: i64,
) -> Result<ProtoOaGetPositionUnrealizedPnLRes, Error> {
let req = ProtoOaGetPositionUnrealizedPnLReq {
payload_type: Some(payload::OA_GET_POSITION_UNREALIZED_PNL_REQ as i32),
ctid_trader_account_id,
};
self.command(
payload::OA_GET_POSITION_UNREALIZED_PNL_REQ,
req,
payload::OA_GET_POSITION_UNREALIZED_PNL_RES,
)
.await
}
}
#[cfg(test)]
mod tests {
#[tokio::test]
async fn test() {}
}