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
///
///
///
///
///
///
///
///
///
///
///
///
///
///
///
use crate::payload;
use crate::proto::common::*;
use crate::{client::Client, error::Error};
impl Client {
/// Application auth
///
///
///
///
///
///
///
///
///
///
pub async fn application_auth(&self) -> Result<(), Error> {
let req = ProtoOaApplicationAuthReq {
payload_type: Some(payload::OA_APPLICATION_AUTH_REQ as i32),
client_id: self.config.client_id.clone(),
client_secret: self.config.client_secret.clone(),
};
let _: ProtoOaApplicationAuthRes = self
.command(
payload::OA_APPLICATION_AUTH_REQ,
req,
payload::OA_APPLICATION_AUTH_RES,
)
.await?;
Ok(())
}
/// Authenticate a trader account. Must be called before any account-scoped
/// request (symbols, deals, orders, …).
///
///
///
///
///
///
///
///
///
/// Mirrors `ProtoOAAccountAuthReq` in the Go integration test.
pub async fn account_auth(
&self,
ctid_trader_account_id: i64,
access_token: &str,
) -> Result<ProtoOaAccountAuthRes, Error> {
let req = ProtoOaAccountAuthReq {
payload_type: Some(payload::OA_ACCOUNT_AUTH_REQ as i32),
ctid_trader_account_id,
access_token: access_token.to_string(),
};
self.command(
payload::OA_ACCOUNT_AUTH_REQ,
req,
payload::OA_ACCOUNT_AUTH_RES,
)
.await
}
/// Refresh an expired access token.
///
///
///
///
///
///
///
///
///
pub async fn refresh_token(
&self,
refresh_token: &str,
) -> Result<ProtoOaRefreshTokenRes, Error> {
let req = ProtoOaRefreshTokenReq {
payload_type: Some(payload::OA_REFRESH_TOKEN_REQ as i32),
refresh_token: refresh_token.to_string(),
};
self.command(
payload::OA_REFRESH_TOKEN_REQ,
req,
payload::OA_REFRESH_TOKEN_RES,
)
.await
}
}
#[cfg(test)]
mod tests {
#[async_std::test]
async fn test() {}
}