exc_binance/http/request/
account.rs1use serde::Serialize;
2
3use crate::http::error::RestError;
4
5use super::{Rest, RestEndpoint};
6
7#[derive(Debug, Clone, Serialize, Default)]
9#[serde(rename_all = "camelCase")]
10pub struct ListSubAccounts {
11 #[serde(skip_serializing_if = "Option::is_none")]
13 pub email: Option<String>,
14 #[serde(skip_serializing_if = "Option::is_none")]
16 pub is_freeze: Option<bool>,
17 #[serde(skip_serializing_if = "Option::is_none")]
19 pub page: Option<usize>,
20 #[serde(skip_serializing_if = "Option::is_none")]
22 pub limit: Option<usize>,
23}
24
25impl Rest for ListSubAccounts {
26 fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
27 Ok(http::Method::GET)
28 }
29
30 fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
31 match endpoint {
32 RestEndpoint::UsdMarginFutures | RestEndpoint::EuropeanOptions => {
33 Err(RestError::UnsupportedEndpoint(anyhow::anyhow!(
34 "`ListSubAccounts` only available on `binance-s`"
35 )))
36 }
37 RestEndpoint::Spot(_options) => Ok("/sapi/v1/sub-account/list".to_string()),
38 }
39 }
40
41 fn need_apikey(&self) -> bool {
42 true
43 }
44
45 fn need_sign(&self) -> bool {
46 true
47 }
48
49 fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
50 Ok(serde_json::to_value(self)?)
51 }
52
53 fn to_payload(&self) -> super::Payload {
54 super::Payload::new(self.clone())
55 }
56}
57
58#[derive(Debug, Clone, Serialize)]
60#[serde(rename_all = "camelCase")]
61pub struct GetSubAccountAssets {
62 pub email: String,
64}
65
66impl Rest for GetSubAccountAssets {
67 fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
68 Ok(http::Method::GET)
69 }
70
71 fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
72 match endpoint {
73 RestEndpoint::UsdMarginFutures | RestEndpoint::EuropeanOptions => {
74 Err(RestError::UnsupportedEndpoint(anyhow::anyhow!(
75 "`GetSubAccountAssets` only available on `binance-s`"
76 )))
77 }
78 RestEndpoint::Spot(_options) => Ok("/sapi/v3/sub-account/assets".to_string()),
79 }
80 }
81
82 fn need_apikey(&self) -> bool {
83 true
84 }
85
86 fn need_sign(&self) -> bool {
87 true
88 }
89
90 fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
91 Ok(serde_json::to_value(self)?)
92 }
93
94 fn to_payload(&self) -> super::Payload {
95 super::Payload::new(self.clone())
96 }
97}
98
99#[derive(Debug, Clone, Serialize)]
101#[serde(rename_all = "camelCase")]
102pub struct GetSubAccountMargin {
103 pub email: String,
105}
106
107impl Rest for GetSubAccountMargin {
108 fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
109 Ok(http::Method::GET)
110 }
111
112 fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
113 match endpoint {
114 RestEndpoint::UsdMarginFutures | RestEndpoint::EuropeanOptions => {
115 Err(RestError::UnsupportedEndpoint(anyhow::anyhow!(
116 "`GetSubAccountMargin` only available on `binance-s`"
117 )))
118 }
119 RestEndpoint::Spot(_options) => Ok("/sapi/v1/sub-account/margin/account".to_string()),
120 }
121 }
122
123 fn need_apikey(&self) -> bool {
124 true
125 }
126
127 fn need_sign(&self) -> bool {
128 true
129 }
130
131 fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
132 Ok(serde_json::to_value(self)?)
133 }
134
135 fn to_payload(&self) -> super::Payload {
136 super::Payload::new(self.clone())
137 }
138}
139
140#[derive(Debug, Clone, Serialize)]
142#[serde(rename_all = "camelCase")]
143pub struct GetSubAccountFutures {
144 pub email: String,
146 pub futures_type: usize,
148}
149
150impl GetSubAccountFutures {
151 pub fn usd(email: &str) -> Self {
153 Self {
154 email: email.to_string(),
155 futures_type: 1,
156 }
157 }
158 pub fn coin(email: &str) -> Self {
160 Self {
161 email: email.to_string(),
162 futures_type: 2,
163 }
164 }
165}
166
167impl Rest for GetSubAccountFutures {
168 fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
169 Ok(http::Method::GET)
170 }
171
172 fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
173 match endpoint {
174 RestEndpoint::UsdMarginFutures | RestEndpoint::EuropeanOptions => {
175 Err(RestError::UnsupportedEndpoint(anyhow::anyhow!(
176 "`GetSubAccountFutures` only available on `binance-s`"
177 )))
178 }
179 RestEndpoint::Spot(_options) => Ok("/sapi/v2/sub-account/futures/account".to_string()),
180 }
181 }
182
183 fn need_apikey(&self) -> bool {
184 true
185 }
186
187 fn need_sign(&self) -> bool {
188 true
189 }
190
191 fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
192 Ok(serde_json::to_value(self)?)
193 }
194
195 fn to_payload(&self) -> super::Payload {
196 super::Payload::new(self.clone())
197 }
198}
199
200#[derive(Debug, Clone, Serialize)]
202#[serde(rename_all = "camelCase")]
203pub struct GetSubAccountFuturesPositions {
204 pub email: String,
206 pub futures_type: usize,
208}
209
210impl GetSubAccountFuturesPositions {
211 pub fn usd(email: &str) -> Self {
213 Self {
214 email: email.to_string(),
215 futures_type: 1,
216 }
217 }
218 pub fn coin(email: &str) -> Self {
220 Self {
221 email: email.to_string(),
222 futures_type: 2,
223 }
224 }
225}
226
227impl Rest for GetSubAccountFuturesPositions {
228 fn method(&self, _endpoint: &RestEndpoint) -> Result<http::Method, RestError> {
229 Ok(http::Method::GET)
230 }
231
232 fn to_path(&self, endpoint: &RestEndpoint) -> Result<String, RestError> {
233 match endpoint {
234 RestEndpoint::UsdMarginFutures | RestEndpoint::EuropeanOptions => {
235 Err(RestError::UnsupportedEndpoint(anyhow::anyhow!(
236 "`GetSubAccountFuturesPositions` only available on `binance-s`"
237 )))
238 }
239 RestEndpoint::Spot(_options) => {
240 Ok("/sapi/v2/sub-account/futures/positionRisk".to_string())
241 }
242 }
243 }
244
245 fn need_apikey(&self) -> bool {
246 true
247 }
248
249 fn need_sign(&self) -> bool {
250 true
251 }
252
253 fn serialize(&self, _endpoint: &RestEndpoint) -> Result<serde_json::Value, RestError> {
254 Ok(serde_json::to_value(self)?)
255 }
256
257 fn to_payload(&self) -> super::Payload {
258 super::Payload::new(self.clone())
259 }
260}