binance/margin/apis/
transfer_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::margin::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct MarginGetMarginMaxTransferableV1Params {
20 pub asset: String,
21 pub timestamp: i64,
22 pub isolated_symbol: Option<String>,
24 pub recv_window: Option<i64>
26}
27
28#[derive(Clone, Debug, Default)]
30pub struct MarginGetMarginTransferV1Params {
31 pub timestamp: i64,
32 pub asset: Option<String>,
33 pub r#type: Option<String>,
35 pub start_time: Option<i64>,
36 pub end_time: Option<i64>,
37 pub current: Option<i64>,
39 pub size: Option<i64>,
41 pub isolated_symbol: Option<String>,
43 pub recv_window: Option<i64>
45}
46
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum MarginGetMarginMaxTransferableV1Error {
52 Status4XX(models::ApiError),
53 Status5XX(models::ApiError),
54 UnknownValue(serde_json::Value),
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum MarginGetMarginTransferV1Error {
61 Status4XX(models::ApiError),
62 Status5XX(models::ApiError),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn margin_get_margin_max_transferable_v1(configuration: &configuration::Configuration, params: MarginGetMarginMaxTransferableV1Params) -> Result<models::MarginGetMarginMaxTransferableV1Resp, Error<MarginGetMarginMaxTransferableV1Error>> {
69
70 let uri_str = format!("{}/sapi/v1/margin/maxTransferable", configuration.base_path);
71 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
72
73 let mut query_params: Vec<(String, String)> = Vec::new();
75
76 query_params.push(("asset".to_string(), params.asset.to_string()));
77 if let Some(ref param_value) = params.isolated_symbol {
78 query_params.push(("isolatedSymbol".to_string(), param_value.to_string()));
79 }
80 if let Some(ref param_value) = params.recv_window {
81 query_params.push(("recvWindow".to_string(), param_value.to_string()));
82 }
83 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
84
85 let mut header_params = std::collections::HashMap::new();
87
88 if let Some(ref binance_auth) = configuration.binance_auth {
90 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
92
93 let body_string: Option<Vec<u8>> = None;
95
96 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
98 Ok(sig) => sig,
99 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
100 };
101
102 query_params.push(("signature".to_string(), signature));
104 }
105
106 if !query_params.is_empty() {
108 req_builder = req_builder.query(&query_params);
109 }
110
111
112 if let Some(ref user_agent) = configuration.user_agent {
114 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115 }
116
117 for (header_name, header_value) in header_params {
119 req_builder = req_builder.header(&header_name, &header_value);
120 }
121
122
123 let req = req_builder.build()?;
124 let resp = configuration.client.execute(req).await?;
125
126 let status = resp.status();
127 let content_type = resp
128 .headers()
129 .get("content-type")
130 .and_then(|v| v.to_str().ok())
131 .unwrap_or("application/octet-stream");
132 let content_type = super::ContentType::from(content_type);
133
134 if !status.is_client_error() && !status.is_server_error() {
135 let content = resp.text().await?;
136 match content_type {
137 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
138 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetMarginMaxTransferableV1Resp`"))),
139 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetMarginMaxTransferableV1Resp`")))),
140 }
141 } else {
142 let content = resp.text().await?;
143 let entity: Option<MarginGetMarginMaxTransferableV1Error> = serde_json::from_str(&content).ok();
144 Err(Error::ResponseError(ResponseContent { status, content, entity }))
145 }
146}
147
148pub async fn margin_get_margin_transfer_v1(configuration: &configuration::Configuration, params: MarginGetMarginTransferV1Params) -> Result<models::MarginGetMarginTransferV1Resp, Error<MarginGetMarginTransferV1Error>> {
150
151 let uri_str = format!("{}/sapi/v1/margin/transfer", configuration.base_path);
152 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
153
154 let mut query_params: Vec<(String, String)> = Vec::new();
156
157 if let Some(ref param_value) = params.asset {
158 query_params.push(("asset".to_string(), param_value.to_string()));
159 }
160 if let Some(ref param_value) = params.r#type {
161 query_params.push(("type".to_string(), param_value.to_string()));
162 }
163 if let Some(ref param_value) = params.start_time {
164 query_params.push(("startTime".to_string(), param_value.to_string()));
165 }
166 if let Some(ref param_value) = params.end_time {
167 query_params.push(("endTime".to_string(), param_value.to_string()));
168 }
169 if let Some(ref param_value) = params.current {
170 query_params.push(("current".to_string(), param_value.to_string()));
171 }
172 if let Some(ref param_value) = params.size {
173 query_params.push(("size".to_string(), param_value.to_string()));
174 }
175 if let Some(ref param_value) = params.isolated_symbol {
176 query_params.push(("isolatedSymbol".to_string(), param_value.to_string()));
177 }
178 if let Some(ref param_value) = params.recv_window {
179 query_params.push(("recvWindow".to_string(), param_value.to_string()));
180 }
181 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
182
183 let mut header_params = std::collections::HashMap::new();
185
186 if let Some(ref binance_auth) = configuration.binance_auth {
188 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
190
191 let body_string: Option<Vec<u8>> = None;
193
194 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
196 Ok(sig) => sig,
197 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
198 };
199
200 query_params.push(("signature".to_string(), signature));
202 }
203
204 if !query_params.is_empty() {
206 req_builder = req_builder.query(&query_params);
207 }
208
209
210 if let Some(ref user_agent) = configuration.user_agent {
212 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213 }
214
215 for (header_name, header_value) in header_params {
217 req_builder = req_builder.header(&header_name, &header_value);
218 }
219
220
221 let req = req_builder.build()?;
222 let resp = configuration.client.execute(req).await?;
223
224 let status = resp.status();
225 let content_type = resp
226 .headers()
227 .get("content-type")
228 .and_then(|v| v.to_str().ok())
229 .unwrap_or("application/octet-stream");
230 let content_type = super::ContentType::from(content_type);
231
232 if !status.is_client_error() && !status.is_server_error() {
233 let content = resp.text().await?;
234 match content_type {
235 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
236 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MarginGetMarginTransferV1Resp`"))),
237 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::MarginGetMarginTransferV1Resp`")))),
238 }
239 } else {
240 let content = resp.text().await?;
241 let entity: Option<MarginGetMarginTransferV1Error> = serde_json::from_str(&content).ok();
242 Err(Error::ResponseError(ResponseContent { status, content, entity }))
243 }
244}
245