binance/spot/apis/
nft_api.rs

1/*
2 * Binance Spot API
3 *
4 * OpenAPI specification for Binance exchange - Spot API
5 *
6 * The version of the OpenAPI document: 0.3.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::spot::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17/// struct for passing parameters to the method [`get_nft_history_deposit_v1`]
18#[derive(Clone, Debug, Default)]
19pub struct GetNftHistoryDepositV1Params {
20    pub timestamp: i64,
21    pub start_time: Option<i64>,
22    pub end_time: Option<i64>,
23    /// Default 50, Max 50
24    pub limit: Option<i32>,
25    /// Default 1
26    pub page: Option<i32>,
27    pub recv_window: Option<i64>
28}
29
30/// struct for passing parameters to the method [`get_nft_history_transactions_v1`]
31#[derive(Clone, Debug, Default)]
32pub struct GetNftHistoryTransactionsV1Params {
33    /// 0: purchase order, 1: sell order, 2: royalty income, 3: primary market order, 4: mint fee
34    pub order_type: i32,
35    pub timestamp: i64,
36    pub start_time: Option<i64>,
37    pub end_time: Option<i64>,
38    /// Default 50, Max 50
39    pub limit: Option<i32>,
40    /// Default 1
41    pub page: Option<i32>,
42    pub recv_window: Option<i64>
43}
44
45/// struct for passing parameters to the method [`get_nft_history_withdraw_v1`]
46#[derive(Clone, Debug, Default)]
47pub struct GetNftHistoryWithdrawV1Params {
48    pub timestamp: i64,
49    pub start_time: Option<i64>,
50    pub end_time: Option<i64>,
51    /// Default 50, Max 50
52    pub limit: Option<i32>,
53    /// Default 1
54    pub page: Option<i32>,
55    pub recv_window: Option<i64>
56}
57
58/// struct for passing parameters to the method [`get_nft_user_get_asset_v1`]
59#[derive(Clone, Debug, Default)]
60pub struct GetNftUserGetAssetV1Params {
61    pub timestamp: i64,
62    /// Default 50, Max 50
63    pub limit: Option<i32>,
64    /// Default 1
65    pub page: Option<i32>,
66    pub recv_window: Option<i64>
67}
68
69
70/// struct for typed errors of method [`get_nft_history_deposit_v1`]
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(untagged)]
73pub enum GetNftHistoryDepositV1Error {
74    Status4XX(models::ApiError),
75    Status5XX(models::ApiError),
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`get_nft_history_transactions_v1`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetNftHistoryTransactionsV1Error {
83    Status4XX(models::ApiError),
84    Status5XX(models::ApiError),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`get_nft_history_withdraw_v1`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum GetNftHistoryWithdrawV1Error {
92    Status4XX(models::ApiError),
93    Status5XX(models::ApiError),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`get_nft_user_get_asset_v1`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum GetNftUserGetAssetV1Error {
101    Status4XX(models::ApiError),
102    Status5XX(models::ApiError),
103    UnknownValue(serde_json::Value),
104}
105
106
107/// et NFT Deposit History
108pub async fn get_nft_history_deposit_v1(configuration: &configuration::Configuration, params: GetNftHistoryDepositV1Params) -> Result<models::GetNftHistoryDepositV1Resp, Error<GetNftHistoryDepositV1Error>> {
109
110    let uri_str = format!("{}/sapi/v1/nft/history/deposit", configuration.base_path);
111    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
112
113    // Create a mutable vector for query parameters
114    let mut query_params: Vec<(String, String)> = Vec::new();
115
116    if let Some(ref param_value) = params.start_time {
117        query_params.push(("startTime".to_string(), param_value.to_string()));
118    }
119    if let Some(ref param_value) = params.end_time {
120        query_params.push(("endTime".to_string(), param_value.to_string()));
121    }
122    if let Some(ref param_value) = params.limit {
123        query_params.push(("limit".to_string(), param_value.to_string()));
124    }
125    if let Some(ref param_value) = params.page {
126        query_params.push(("page".to_string(), param_value.to_string()));
127    }
128    if let Some(ref param_value) = params.recv_window {
129        query_params.push(("recvWindow".to_string(), param_value.to_string()));
130    }
131    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
132
133    // Create header parameters collection
134    let mut header_params = std::collections::HashMap::new();
135
136    // Handle Binance Auth first if configured
137    if let Some(ref binance_auth) = configuration.binance_auth {
138        // Add API key to headers
139        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
140        
141        // Generate request body for signing (if any)
142        let body_string: Option<Vec<u8>> = None;
143        
144        // Sign the request
145        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
146            Ok(sig) => sig,
147            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
148        };
149        
150        // Add signature to query params
151        query_params.push(("signature".to_string(), signature));
152    }
153
154    // Apply all query parameters
155    if !query_params.is_empty() {
156        req_builder = req_builder.query(&query_params);
157    }
158
159
160    // Add user agent if configured
161    if let Some(ref user_agent) = configuration.user_agent {
162        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
163    }
164
165    // Apply all header parameters
166    for (header_name, header_value) in header_params {
167        req_builder = req_builder.header(&header_name, &header_value);
168    }
169
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175    let content_type = resp
176        .headers()
177        .get("content-type")
178        .and_then(|v| v.to_str().ok())
179        .unwrap_or("application/octet-stream");
180    let content_type = super::ContentType::from(content_type);
181
182    if !status.is_client_error() && !status.is_server_error() {
183        let content = resp.text().await?;
184        match content_type {
185            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetNftHistoryDepositV1Resp`"))),
187            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::GetNftHistoryDepositV1Resp`")))),
188        }
189    } else {
190        let content = resp.text().await?;
191        let entity: Option<GetNftHistoryDepositV1Error> = serde_json::from_str(&content).ok();
192        Err(Error::ResponseError(ResponseContent { status, content, entity }))
193    }
194}
195
196/// Get NFT Transaction History
197pub async fn get_nft_history_transactions_v1(configuration: &configuration::Configuration, params: GetNftHistoryTransactionsV1Params) -> Result<models::GetNftHistoryTransactionsV1Resp, Error<GetNftHistoryTransactionsV1Error>> {
198
199    let uri_str = format!("{}/sapi/v1/nft/history/transactions", configuration.base_path);
200    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
201
202    // Create a mutable vector for query parameters
203    let mut query_params: Vec<(String, String)> = Vec::new();
204
205    query_params.push(("orderType".to_string(), params.order_type.to_string()));
206    if let Some(ref param_value) = params.start_time {
207        query_params.push(("startTime".to_string(), param_value.to_string()));
208    }
209    if let Some(ref param_value) = params.end_time {
210        query_params.push(("endTime".to_string(), param_value.to_string()));
211    }
212    if let Some(ref param_value) = params.limit {
213        query_params.push(("limit".to_string(), param_value.to_string()));
214    }
215    if let Some(ref param_value) = params.page {
216        query_params.push(("page".to_string(), param_value.to_string()));
217    }
218    if let Some(ref param_value) = params.recv_window {
219        query_params.push(("recvWindow".to_string(), param_value.to_string()));
220    }
221    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
222
223    // Create header parameters collection
224    let mut header_params = std::collections::HashMap::new();
225
226    // Handle Binance Auth first if configured
227    if let Some(ref binance_auth) = configuration.binance_auth {
228        // Add API key to headers
229        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
230        
231        // Generate request body for signing (if any)
232        let body_string: Option<Vec<u8>> = None;
233        
234        // Sign the request
235        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
236            Ok(sig) => sig,
237            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
238        };
239        
240        // Add signature to query params
241        query_params.push(("signature".to_string(), signature));
242    }
243
244    // Apply all query parameters
245    if !query_params.is_empty() {
246        req_builder = req_builder.query(&query_params);
247    }
248
249
250    // Add user agent if configured
251    if let Some(ref user_agent) = configuration.user_agent {
252        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
253    }
254
255    // Apply all header parameters
256    for (header_name, header_value) in header_params {
257        req_builder = req_builder.header(&header_name, &header_value);
258    }
259
260
261    let req = req_builder.build()?;
262    let resp = configuration.client.execute(req).await?;
263
264    let status = resp.status();
265    let content_type = resp
266        .headers()
267        .get("content-type")
268        .and_then(|v| v.to_str().ok())
269        .unwrap_or("application/octet-stream");
270    let content_type = super::ContentType::from(content_type);
271
272    if !status.is_client_error() && !status.is_server_error() {
273        let content = resp.text().await?;
274        match content_type {
275            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
276            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetNftHistoryTransactionsV1Resp`"))),
277            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::GetNftHistoryTransactionsV1Resp`")))),
278        }
279    } else {
280        let content = resp.text().await?;
281        let entity: Option<GetNftHistoryTransactionsV1Error> = serde_json::from_str(&content).ok();
282        Err(Error::ResponseError(ResponseContent { status, content, entity }))
283    }
284}
285
286/// Get NFT Withdraw History
287pub async fn get_nft_history_withdraw_v1(configuration: &configuration::Configuration, params: GetNftHistoryWithdrawV1Params) -> Result<models::GetNftHistoryWithdrawV1Resp, Error<GetNftHistoryWithdrawV1Error>> {
288
289    let uri_str = format!("{}/sapi/v1/nft/history/withdraw", configuration.base_path);
290    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
291
292    // Create a mutable vector for query parameters
293    let mut query_params: Vec<(String, String)> = Vec::new();
294
295    if let Some(ref param_value) = params.start_time {
296        query_params.push(("startTime".to_string(), param_value.to_string()));
297    }
298    if let Some(ref param_value) = params.end_time {
299        query_params.push(("endTime".to_string(), param_value.to_string()));
300    }
301    if let Some(ref param_value) = params.limit {
302        query_params.push(("limit".to_string(), param_value.to_string()));
303    }
304    if let Some(ref param_value) = params.page {
305        query_params.push(("page".to_string(), param_value.to_string()));
306    }
307    if let Some(ref param_value) = params.recv_window {
308        query_params.push(("recvWindow".to_string(), param_value.to_string()));
309    }
310    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
311
312    // Create header parameters collection
313    let mut header_params = std::collections::HashMap::new();
314
315    // Handle Binance Auth first if configured
316    if let Some(ref binance_auth) = configuration.binance_auth {
317        // Add API key to headers
318        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
319        
320        // Generate request body for signing (if any)
321        let body_string: Option<Vec<u8>> = None;
322        
323        // Sign the request
324        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
325            Ok(sig) => sig,
326            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
327        };
328        
329        // Add signature to query params
330        query_params.push(("signature".to_string(), signature));
331    }
332
333    // Apply all query parameters
334    if !query_params.is_empty() {
335        req_builder = req_builder.query(&query_params);
336    }
337
338
339    // Add user agent if configured
340    if let Some(ref user_agent) = configuration.user_agent {
341        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
342    }
343
344    // Apply all header parameters
345    for (header_name, header_value) in header_params {
346        req_builder = req_builder.header(&header_name, &header_value);
347    }
348
349
350    let req = req_builder.build()?;
351    let resp = configuration.client.execute(req).await?;
352
353    let status = resp.status();
354    let content_type = resp
355        .headers()
356        .get("content-type")
357        .and_then(|v| v.to_str().ok())
358        .unwrap_or("application/octet-stream");
359    let content_type = super::ContentType::from(content_type);
360
361    if !status.is_client_error() && !status.is_server_error() {
362        let content = resp.text().await?;
363        match content_type {
364            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
365            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetNftHistoryWithdrawV1Resp`"))),
366            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::GetNftHistoryWithdrawV1Resp`")))),
367        }
368    } else {
369        let content = resp.text().await?;
370        let entity: Option<GetNftHistoryWithdrawV1Error> = serde_json::from_str(&content).ok();
371        Err(Error::ResponseError(ResponseContent { status, content, entity }))
372    }
373}
374
375/// Get NFT Asset
376pub async fn get_nft_user_get_asset_v1(configuration: &configuration::Configuration, params: GetNftUserGetAssetV1Params) -> Result<models::GetNftUserGetAssetV1Resp, Error<GetNftUserGetAssetV1Error>> {
377
378    let uri_str = format!("{}/sapi/v1/nft/user/getAsset", configuration.base_path);
379    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
380
381    // Create a mutable vector for query parameters
382    let mut query_params: Vec<(String, String)> = Vec::new();
383
384    if let Some(ref param_value) = params.limit {
385        query_params.push(("limit".to_string(), param_value.to_string()));
386    }
387    if let Some(ref param_value) = params.page {
388        query_params.push(("page".to_string(), param_value.to_string()));
389    }
390    if let Some(ref param_value) = params.recv_window {
391        query_params.push(("recvWindow".to_string(), param_value.to_string()));
392    }
393    query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
394
395    // Create header parameters collection
396    let mut header_params = std::collections::HashMap::new();
397
398    // Handle Binance Auth first if configured
399    if let Some(ref binance_auth) = configuration.binance_auth {
400        // Add API key to headers
401        header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
402        
403        // Generate request body for signing (if any)
404        let body_string: Option<Vec<u8>> = None;
405        
406        // Sign the request
407        let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
408            Ok(sig) => sig,
409            Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
410        };
411        
412        // Add signature to query params
413        query_params.push(("signature".to_string(), signature));
414    }
415
416    // Apply all query parameters
417    if !query_params.is_empty() {
418        req_builder = req_builder.query(&query_params);
419    }
420
421
422    // Add user agent if configured
423    if let Some(ref user_agent) = configuration.user_agent {
424        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
425    }
426
427    // Apply all header parameters
428    for (header_name, header_value) in header_params {
429        req_builder = req_builder.header(&header_name, &header_value);
430    }
431
432
433    let req = req_builder.build()?;
434    let resp = configuration.client.execute(req).await?;
435
436    let status = resp.status();
437    let content_type = resp
438        .headers()
439        .get("content-type")
440        .and_then(|v| v.to_str().ok())
441        .unwrap_or("application/octet-stream");
442    let content_type = super::ContentType::from(content_type);
443
444    if !status.is_client_error() && !status.is_server_error() {
445        let content = resp.text().await?;
446        match content_type {
447            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
448            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetNftUserGetAssetV1Resp`"))),
449            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::GetNftUserGetAssetV1Resp`")))),
450        }
451    } else {
452        let content = resp.text().await?;
453        let entity: Option<GetNftUserGetAssetV1Error> = serde_json::from_str(&content).ok();
454        Err(Error::ResponseError(ResponseContent { status, content, entity }))
455    }
456}
457