binance/convert/apis/
market_data_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::convert::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct ConvertGetConvertAssetInfoV1Params {
20 pub timestamp: i64,
21 pub recv_window: Option<i64>
23}
24
25#[derive(Clone, Debug, Default)]
27pub struct ConvertGetConvertExchangeInfoV1Params {
28 pub from_asset: Option<String>,
30 pub to_asset: Option<String>
32}
33
34
35#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum ConvertGetConvertAssetInfoV1Error {
39 Status4XX(models::ApiError),
40 Status5XX(models::ApiError),
41 UnknownValue(serde_json::Value),
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum ConvertGetConvertExchangeInfoV1Error {
48 Status4XX(models::ApiError),
49 Status5XX(models::ApiError),
50 UnknownValue(serde_json::Value),
51}
52
53
54pub async fn convert_get_convert_asset_info_v1(configuration: &configuration::Configuration, params: ConvertGetConvertAssetInfoV1Params) -> Result<Vec<models::ConvertGetConvertAssetInfoV1RespItem>, Error<ConvertGetConvertAssetInfoV1Error>> {
56
57 let uri_str = format!("{}/sapi/v1/convert/assetInfo", configuration.base_path);
58 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
59
60 let mut query_params: Vec<(String, String)> = Vec::new();
62
63 if let Some(ref param_value) = params.recv_window {
64 query_params.push(("recvWindow".to_string(), param_value.to_string()));
65 }
66 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
67
68 let mut header_params = std::collections::HashMap::new();
70
71 if let Some(ref binance_auth) = configuration.binance_auth {
73 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
75
76 let body_string: Option<Vec<u8>> = None;
78
79 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
81 Ok(sig) => sig,
82 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
83 };
84
85 query_params.push(("signature".to_string(), signature));
87 }
88
89 if !query_params.is_empty() {
91 req_builder = req_builder.query(&query_params);
92 }
93
94
95 if let Some(ref user_agent) = configuration.user_agent {
97 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
98 }
99
100 for (header_name, header_value) in header_params {
102 req_builder = req_builder.header(&header_name, &header_value);
103 }
104
105
106 let req = req_builder.build()?;
107 let resp = configuration.client.execute(req).await?;
108
109 let status = resp.status();
110 let content_type = resp
111 .headers()
112 .get("content-type")
113 .and_then(|v| v.to_str().ok())
114 .unwrap_or("application/octet-stream");
115 let content_type = super::ContentType::from(content_type);
116
117 if !status.is_client_error() && !status.is_server_error() {
118 let content = resp.text().await?;
119 match content_type {
120 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
121 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ConvertGetConvertAssetInfoV1RespItem>`"))),
122 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::ConvertGetConvertAssetInfoV1RespItem>`")))),
123 }
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<ConvertGetConvertAssetInfoV1Error> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn convert_get_convert_exchange_info_v1(configuration: &configuration::Configuration, params: ConvertGetConvertExchangeInfoV1Params) -> Result<Vec<models::ConvertGetConvertExchangeInfoV1RespItem>, Error<ConvertGetConvertExchangeInfoV1Error>> {
133
134 let uri_str = format!("{}/sapi/v1/convert/exchangeInfo", configuration.base_path);
135 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
136
137 let mut query_params: Vec<(String, String)> = Vec::new();
139
140 if let Some(ref param_value) = params.from_asset {
141 query_params.push(("fromAsset".to_string(), param_value.to_string()));
142 }
143 if let Some(ref param_value) = params.to_asset {
144 query_params.push(("toAsset".to_string(), param_value.to_string()));
145 }
146
147 let mut header_params = std::collections::HashMap::new();
149
150 if let Some(ref binance_auth) = configuration.binance_auth {
152 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
154
155 let body_string: Option<Vec<u8>> = None;
157
158 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
160 Ok(sig) => sig,
161 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
162 };
163
164 query_params.push(("signature".to_string(), signature));
166 }
167
168 if !query_params.is_empty() {
170 req_builder = req_builder.query(&query_params);
171 }
172
173
174 if let Some(ref user_agent) = configuration.user_agent {
176 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177 }
178
179 for (header_name, header_value) in header_params {
181 req_builder = req_builder.header(&header_name, &header_value);
182 }
183
184
185 let req = req_builder.build()?;
186 let resp = configuration.client.execute(req).await?;
187
188 let status = resp.status();
189 let content_type = resp
190 .headers()
191 .get("content-type")
192 .and_then(|v| v.to_str().ok())
193 .unwrap_or("application/octet-stream");
194 let content_type = super::ContentType::from(content_type);
195
196 if !status.is_client_error() && !status.is_server_error() {
197 let content = resp.text().await?;
198 match content_type {
199 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
200 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ConvertGetConvertExchangeInfoV1RespItem>`"))),
201 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::ConvertGetConvertExchangeInfoV1RespItem>`")))),
202 }
203 } else {
204 let content = resp.text().await?;
205 let entity: Option<ConvertGetConvertExchangeInfoV1Error> = serde_json::from_str(&content).ok();
206 Err(Error::ResponseError(ResponseContent { status, content, entity }))
207 }
208}
209