1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::spot::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug, Default)]
19pub struct CreateGiftcardBuyCodeV1Params {
20 pub base_token: String,
21 pub base_token_amount: f64,
22 pub face_token: String,
23 pub timestamp: i64,
24 pub recv_window: Option<i64>
25}
26
27#[derive(Clone, Debug, Default)]
29pub struct CreateGiftcardCreateCodeV1Params {
30 pub amount: f64,
31 pub timestamp: i64,
32 pub token: String,
33 pub recv_window: Option<i64>
34}
35
36#[derive(Clone, Debug, Default)]
38pub struct CreateGiftcardRedeemCodeV1Params {
39 pub code: String,
40 pub timestamp: i64,
41 pub external_uid: Option<String>,
42 pub recv_window: Option<i64>
43}
44
45#[derive(Clone, Debug, Default)]
47pub struct GetGiftcardBuyCodeTokenLimitV1Params {
48 pub base_token: String,
50 pub timestamp: i64,
51 pub recv_window: Option<i64>
52}
53
54#[derive(Clone, Debug, Default)]
56pub struct GetGiftcardCryptographyRsaPublicKeyV1Params {
57 pub timestamp: i64,
58 pub recv_window: Option<i64>
59}
60
61#[derive(Clone, Debug, Default)]
63pub struct GetGiftcardVerifyV1Params {
64 pub reference_no: String,
66 pub timestamp: i64,
67 pub recv_window: Option<i64>
68}
69
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum CreateGiftcardBuyCodeV1Error {
75 Status4XX(models::ApiError),
76 Status5XX(models::ApiError),
77 UnknownValue(serde_json::Value),
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum CreateGiftcardCreateCodeV1Error {
84 Status4XX(models::ApiError),
85 Status5XX(models::ApiError),
86 UnknownValue(serde_json::Value),
87}
88
89#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(untagged)]
92pub enum CreateGiftcardRedeemCodeV1Error {
93 Status4XX(models::ApiError),
94 Status5XX(models::ApiError),
95 UnknownValue(serde_json::Value),
96}
97
98#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(untagged)]
101pub enum GetGiftcardBuyCodeTokenLimitV1Error {
102 Status4XX(models::ApiError),
103 Status5XX(models::ApiError),
104 UnknownValue(serde_json::Value),
105}
106
107#[derive(Debug, Clone, Serialize, Deserialize)]
109#[serde(untagged)]
110pub enum GetGiftcardCryptographyRsaPublicKeyV1Error {
111 Status4XX(models::ApiError),
112 Status5XX(models::ApiError),
113 UnknownValue(serde_json::Value),
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118#[serde(untagged)]
119pub enum GetGiftcardVerifyV1Error {
120 Status4XX(models::ApiError),
121 Status5XX(models::ApiError),
122 UnknownValue(serde_json::Value),
123}
124
125
126pub async fn create_giftcard_buy_code_v1(configuration: &configuration::Configuration, params: CreateGiftcardBuyCodeV1Params) -> Result<models::CreateGiftcardBuyCodeV1Resp, Error<CreateGiftcardBuyCodeV1Error>> {
128
129 let uri_str = format!("{}/sapi/v1/giftcard/buyCode", configuration.base_path);
130 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
131
132 let mut query_params: Vec<(String, String)> = Vec::new();
134
135
136 let mut header_params = std::collections::HashMap::new();
138
139 if let Some(ref binance_auth) = configuration.binance_auth {
141 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
143
144 let body_string: Option<Vec<u8>> = None;
146
147 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
149 Ok(sig) => sig,
150 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
151 };
152
153 query_params.push(("signature".to_string(), signature));
155 }
156
157 if !query_params.is_empty() {
159 req_builder = req_builder.query(&query_params);
160 }
161
162
163 if let Some(ref user_agent) = configuration.user_agent {
165 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166 }
167
168 for (header_name, header_value) in header_params {
170 req_builder = req_builder.header(&header_name, &header_value);
171 }
172
173 let mut multipart_form_params = std::collections::HashMap::new();
174 multipart_form_params.insert("baseToken", params.base_token.to_string());
175 multipart_form_params.insert("baseTokenAmount", params.base_token_amount.to_string());
176 multipart_form_params.insert("faceToken", params.face_token.to_string());
177 if let Some(param_value) = params.recv_window {
178 multipart_form_params.insert("recvWindow", param_value.to_string());
179 }
180 multipart_form_params.insert("timestamp", params.timestamp.to_string());
181 req_builder = req_builder.form(&multipart_form_params);
182
183 let req = req_builder.build()?;
184 let resp = configuration.client.execute(req).await?;
185
186 let status = resp.status();
187 let content_type = resp
188 .headers()
189 .get("content-type")
190 .and_then(|v| v.to_str().ok())
191 .unwrap_or("application/octet-stream");
192 let content_type = super::ContentType::from(content_type);
193
194 if !status.is_client_error() && !status.is_server_error() {
195 let content = resp.text().await?;
196 match content_type {
197 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
198 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateGiftcardBuyCodeV1Resp`"))),
199 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::CreateGiftcardBuyCodeV1Resp`")))),
200 }
201 } else {
202 let content = resp.text().await?;
203 let entity: Option<CreateGiftcardBuyCodeV1Error> = serde_json::from_str(&content).ok();
204 Err(Error::ResponseError(ResponseContent { status, content, entity }))
205 }
206}
207
208pub async fn create_giftcard_create_code_v1(configuration: &configuration::Configuration, params: CreateGiftcardCreateCodeV1Params) -> Result<models::CreateGiftcardCreateCodeV1Resp, Error<CreateGiftcardCreateCodeV1Error>> {
210
211 let uri_str = format!("{}/sapi/v1/giftcard/createCode", configuration.base_path);
212 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
213
214 let mut query_params: Vec<(String, String)> = Vec::new();
216
217
218 let mut header_params = std::collections::HashMap::new();
220
221 if let Some(ref binance_auth) = configuration.binance_auth {
223 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
225
226 let body_string: Option<Vec<u8>> = None;
228
229 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
231 Ok(sig) => sig,
232 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
233 };
234
235 query_params.push(("signature".to_string(), signature));
237 }
238
239 if !query_params.is_empty() {
241 req_builder = req_builder.query(&query_params);
242 }
243
244
245 if let Some(ref user_agent) = configuration.user_agent {
247 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
248 }
249
250 for (header_name, header_value) in header_params {
252 req_builder = req_builder.header(&header_name, &header_value);
253 }
254
255 let mut multipart_form_params = std::collections::HashMap::new();
256 multipart_form_params.insert("amount", params.amount.to_string());
257 if let Some(param_value) = params.recv_window {
258 multipart_form_params.insert("recvWindow", param_value.to_string());
259 }
260 multipart_form_params.insert("timestamp", params.timestamp.to_string());
261 multipart_form_params.insert("token", params.token.to_string());
262 req_builder = req_builder.form(&multipart_form_params);
263
264 let req = req_builder.build()?;
265 let resp = configuration.client.execute(req).await?;
266
267 let status = resp.status();
268 let content_type = resp
269 .headers()
270 .get("content-type")
271 .and_then(|v| v.to_str().ok())
272 .unwrap_or("application/octet-stream");
273 let content_type = super::ContentType::from(content_type);
274
275 if !status.is_client_error() && !status.is_server_error() {
276 let content = resp.text().await?;
277 match content_type {
278 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
279 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateGiftcardCreateCodeV1Resp`"))),
280 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::CreateGiftcardCreateCodeV1Resp`")))),
281 }
282 } else {
283 let content = resp.text().await?;
284 let entity: Option<CreateGiftcardCreateCodeV1Error> = serde_json::from_str(&content).ok();
285 Err(Error::ResponseError(ResponseContent { status, content, entity }))
286 }
287}
288
289pub async fn create_giftcard_redeem_code_v1(configuration: &configuration::Configuration, params: CreateGiftcardRedeemCodeV1Params) -> Result<models::CreateGiftcardRedeemCodeV1Resp, Error<CreateGiftcardRedeemCodeV1Error>> {
291
292 let uri_str = format!("{}/sapi/v1/giftcard/redeemCode", configuration.base_path);
293 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
294
295 let mut query_params: Vec<(String, String)> = Vec::new();
297
298
299 let mut header_params = std::collections::HashMap::new();
301
302 if let Some(ref binance_auth) = configuration.binance_auth {
304 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
306
307 let body_string: Option<Vec<u8>> = None;
309
310 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
312 Ok(sig) => sig,
313 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
314 };
315
316 query_params.push(("signature".to_string(), signature));
318 }
319
320 if !query_params.is_empty() {
322 req_builder = req_builder.query(&query_params);
323 }
324
325
326 if let Some(ref user_agent) = configuration.user_agent {
328 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
329 }
330
331 for (header_name, header_value) in header_params {
333 req_builder = req_builder.header(&header_name, &header_value);
334 }
335
336 let mut multipart_form_params = std::collections::HashMap::new();
337 multipart_form_params.insert("code", params.code.to_string());
338 if let Some(param_value) = params.external_uid {
339 multipart_form_params.insert("externalUid", param_value.to_string());
340 }
341 if let Some(param_value) = params.recv_window {
342 multipart_form_params.insert("recvWindow", param_value.to_string());
343 }
344 multipart_form_params.insert("timestamp", params.timestamp.to_string());
345 req_builder = req_builder.form(&multipart_form_params);
346
347 let req = req_builder.build()?;
348 let resp = configuration.client.execute(req).await?;
349
350 let status = resp.status();
351 let content_type = resp
352 .headers()
353 .get("content-type")
354 .and_then(|v| v.to_str().ok())
355 .unwrap_or("application/octet-stream");
356 let content_type = super::ContentType::from(content_type);
357
358 if !status.is_client_error() && !status.is_server_error() {
359 let content = resp.text().await?;
360 match content_type {
361 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
362 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateGiftcardRedeemCodeV1Resp`"))),
363 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::CreateGiftcardRedeemCodeV1Resp`")))),
364 }
365 } else {
366 let content = resp.text().await?;
367 let entity: Option<CreateGiftcardRedeemCodeV1Error> = serde_json::from_str(&content).ok();
368 Err(Error::ResponseError(ResponseContent { status, content, entity }))
369 }
370}
371
372pub async fn get_giftcard_buy_code_token_limit_v1(configuration: &configuration::Configuration, params: GetGiftcardBuyCodeTokenLimitV1Params) -> Result<models::GetGiftcardBuyCodeTokenLimitV1Resp, Error<GetGiftcardBuyCodeTokenLimitV1Error>> {
374
375 let uri_str = format!("{}/sapi/v1/giftcard/buyCode/token-limit", configuration.base_path);
376 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
377
378 let mut query_params: Vec<(String, String)> = Vec::new();
380
381 query_params.push(("baseToken".to_string(), params.base_token.to_string()));
382 if let Some(ref param_value) = params.recv_window {
383 query_params.push(("recvWindow".to_string(), param_value.to_string()));
384 }
385 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
386
387 let mut header_params = std::collections::HashMap::new();
389
390 if let Some(ref binance_auth) = configuration.binance_auth {
392 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
394
395 let body_string: Option<Vec<u8>> = None;
397
398 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
400 Ok(sig) => sig,
401 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
402 };
403
404 query_params.push(("signature".to_string(), signature));
406 }
407
408 if !query_params.is_empty() {
410 req_builder = req_builder.query(&query_params);
411 }
412
413
414 if let Some(ref user_agent) = configuration.user_agent {
416 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
417 }
418
419 for (header_name, header_value) in header_params {
421 req_builder = req_builder.header(&header_name, &header_value);
422 }
423
424
425 let req = req_builder.build()?;
426 let resp = configuration.client.execute(req).await?;
427
428 let status = resp.status();
429 let content_type = resp
430 .headers()
431 .get("content-type")
432 .and_then(|v| v.to_str().ok())
433 .unwrap_or("application/octet-stream");
434 let content_type = super::ContentType::from(content_type);
435
436 if !status.is_client_error() && !status.is_server_error() {
437 let content = resp.text().await?;
438 match content_type {
439 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
440 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetGiftcardBuyCodeTokenLimitV1Resp`"))),
441 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::GetGiftcardBuyCodeTokenLimitV1Resp`")))),
442 }
443 } else {
444 let content = resp.text().await?;
445 let entity: Option<GetGiftcardBuyCodeTokenLimitV1Error> = serde_json::from_str(&content).ok();
446 Err(Error::ResponseError(ResponseContent { status, content, entity }))
447 }
448}
449
450pub async fn get_giftcard_cryptography_rsa_public_key_v1(configuration: &configuration::Configuration, params: GetGiftcardCryptographyRsaPublicKeyV1Params) -> Result<models::GetGiftcardCryptographyRsaPublicKeyV1Resp, Error<GetGiftcardCryptographyRsaPublicKeyV1Error>> {
452
453 let uri_str = format!("{}/sapi/v1/giftcard/cryptography/rsa-public-key", configuration.base_path);
454 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
455
456 let mut query_params: Vec<(String, String)> = Vec::new();
458
459 if let Some(ref param_value) = params.recv_window {
460 query_params.push(("recvWindow".to_string(), param_value.to_string()));
461 }
462 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
463
464 let mut header_params = std::collections::HashMap::new();
466
467 if let Some(ref binance_auth) = configuration.binance_auth {
469 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
471
472 let body_string: Option<Vec<u8>> = None;
474
475 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
477 Ok(sig) => sig,
478 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
479 };
480
481 query_params.push(("signature".to_string(), signature));
483 }
484
485 if !query_params.is_empty() {
487 req_builder = req_builder.query(&query_params);
488 }
489
490
491 if let Some(ref user_agent) = configuration.user_agent {
493 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
494 }
495
496 for (header_name, header_value) in header_params {
498 req_builder = req_builder.header(&header_name, &header_value);
499 }
500
501
502 let req = req_builder.build()?;
503 let resp = configuration.client.execute(req).await?;
504
505 let status = resp.status();
506 let content_type = resp
507 .headers()
508 .get("content-type")
509 .and_then(|v| v.to_str().ok())
510 .unwrap_or("application/octet-stream");
511 let content_type = super::ContentType::from(content_type);
512
513 if !status.is_client_error() && !status.is_server_error() {
514 let content = resp.text().await?;
515 match content_type {
516 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
517 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetGiftcardCryptographyRsaPublicKeyV1Resp`"))),
518 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::GetGiftcardCryptographyRsaPublicKeyV1Resp`")))),
519 }
520 } else {
521 let content = resp.text().await?;
522 let entity: Option<GetGiftcardCryptographyRsaPublicKeyV1Error> = serde_json::from_str(&content).ok();
523 Err(Error::ResponseError(ResponseContent { status, content, entity }))
524 }
525}
526
527pub async fn get_giftcard_verify_v1(configuration: &configuration::Configuration, params: GetGiftcardVerifyV1Params) -> Result<models::GetGiftcardVerifyV1Resp, Error<GetGiftcardVerifyV1Error>> {
529
530 let uri_str = format!("{}/sapi/v1/giftcard/verify", configuration.base_path);
531 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
532
533 let mut query_params: Vec<(String, String)> = Vec::new();
535
536 query_params.push(("referenceNo".to_string(), params.reference_no.to_string()));
537 if let Some(ref param_value) = params.recv_window {
538 query_params.push(("recvWindow".to_string(), param_value.to_string()));
539 }
540 query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
541
542 let mut header_params = std::collections::HashMap::new();
544
545 if let Some(ref binance_auth) = configuration.binance_auth {
547 header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
549
550 let body_string: Option<Vec<u8>> = None;
552
553 let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
555 Ok(sig) => sig,
556 Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
557 };
558
559 query_params.push(("signature".to_string(), signature));
561 }
562
563 if !query_params.is_empty() {
565 req_builder = req_builder.query(&query_params);
566 }
567
568
569 if let Some(ref user_agent) = configuration.user_agent {
571 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
572 }
573
574 for (header_name, header_value) in header_params {
576 req_builder = req_builder.header(&header_name, &header_value);
577 }
578
579
580 let req = req_builder.build()?;
581 let resp = configuration.client.execute(req).await?;
582
583 let status = resp.status();
584 let content_type = resp
585 .headers()
586 .get("content-type")
587 .and_then(|v| v.to_str().ok())
588 .unwrap_or("application/octet-stream");
589 let content_type = super::ContentType::from(content_type);
590
591 if !status.is_client_error() && !status.is_server_error() {
592 let content = resp.text().await?;
593 match content_type {
594 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
595 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetGiftcardVerifyV1Resp`"))),
596 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::GetGiftcardVerifyV1Resp`")))),
597 }
598 } else {
599 let content = resp.text().await?;
600 let entity: Option<GetGiftcardVerifyV1Error> = serde_json::from_str(&content).ok();
601 Err(Error::ResponseError(ResponseContent { status, content, entity }))
602 }
603}
604