use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::convert::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Clone, Debug, Default)]
pub struct ConvertCreateConvertAcceptQuoteV1Params {
pub quote_id: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
#[derive(Clone, Debug, Default)]
pub struct ConvertCreateConvertGetQuoteV1Params {
pub from_asset: String,
pub timestamp: i64,
pub to_asset: String,
pub from_amount: Option<String>,
pub recv_window: Option<i64>,
pub to_amount: Option<String>,
pub valid_time: Option<String>,
pub wallet_type: Option<String>
}
#[derive(Clone, Debug, Default)]
pub struct ConvertCreateConvertLimitCancelOrderV1Params {
pub order_id: i64,
pub timestamp: i64,
pub recv_window: Option<i64>
}
#[derive(Clone, Debug, Default)]
pub struct ConvertCreateConvertLimitPlaceOrderV1Params {
pub base_asset: String,
pub expired_type: String,
pub limit_price: String,
pub quote_asset: String,
pub side: String,
pub timestamp: i64,
pub base_amount: Option<String>,
pub quote_amount: Option<String>,
pub recv_window: Option<i64>,
pub wallet_type: Option<String>
}
#[derive(Clone, Debug, Default)]
pub struct ConvertCreateConvertLimitQueryOpenOrdersV1Params {
pub timestamp: i64,
pub recv_window: Option<i64>
}
#[derive(Clone, Debug, Default)]
pub struct ConvertGetConvertOrderStatusV1Params {
pub order_id: Option<String>,
pub quote_id: Option<String>
}
#[derive(Clone, Debug, Default)]
pub struct ConvertGetConvertTradeFlowV1Params {
pub start_time: i64,
pub end_time: i64,
pub timestamp: i64,
pub limit: Option<i32>,
pub recv_window: Option<i64>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertCreateConvertAcceptQuoteV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertCreateConvertGetQuoteV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertCreateConvertLimitCancelOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertCreateConvertLimitPlaceOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertCreateConvertLimitQueryOpenOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertGetConvertOrderStatusV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertGetConvertTradeFlowV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
pub async fn convert_create_convert_accept_quote_v1(configuration: &configuration::Configuration, params: ConvertCreateConvertAcceptQuoteV1Params) -> Result<models::ConvertCreateConvertAcceptQuoteV1Resp, Error<ConvertCreateConvertAcceptQuoteV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/acceptQuote", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let mut multipart_form_params = std::collections::HashMap::new();
multipart_form_params.insert("quoteId", params.quote_id.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("timestamp", params.timestamp.to_string());
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertCreateConvertAcceptQuoteV1Resp`"))),
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::ConvertCreateConvertAcceptQuoteV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertCreateConvertAcceptQuoteV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn convert_create_convert_get_quote_v1(configuration: &configuration::Configuration, params: ConvertCreateConvertGetQuoteV1Params) -> Result<models::ConvertCreateConvertGetQuoteV1Resp, Error<ConvertCreateConvertGetQuoteV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/getQuote", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let mut multipart_form_params = std::collections::HashMap::new();
if let Some(param_value) = params.from_amount {
multipart_form_params.insert("fromAmount", param_value.to_string());
}
multipart_form_params.insert("fromAsset", params.from_asset.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("timestamp", params.timestamp.to_string());
if let Some(param_value) = params.to_amount {
multipart_form_params.insert("toAmount", param_value.to_string());
}
multipart_form_params.insert("toAsset", params.to_asset.to_string());
if let Some(param_value) = params.valid_time {
multipart_form_params.insert("validTime", param_value.to_string());
}
if let Some(param_value) = params.wallet_type {
multipart_form_params.insert("walletType", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertCreateConvertGetQuoteV1Resp`"))),
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::ConvertCreateConvertGetQuoteV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertCreateConvertGetQuoteV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn convert_create_convert_limit_cancel_order_v1(configuration: &configuration::Configuration, params: ConvertCreateConvertLimitCancelOrderV1Params) -> Result<models::ConvertCreateConvertLimitCancelOrderV1Resp, Error<ConvertCreateConvertLimitCancelOrderV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/limit/cancelOrder", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let mut multipart_form_params = std::collections::HashMap::new();
multipart_form_params.insert("orderId", params.order_id.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("timestamp", params.timestamp.to_string());
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertCreateConvertLimitCancelOrderV1Resp`"))),
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::ConvertCreateConvertLimitCancelOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertCreateConvertLimitCancelOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn convert_create_convert_limit_place_order_v1(configuration: &configuration::Configuration, params: ConvertCreateConvertLimitPlaceOrderV1Params) -> Result<models::ConvertCreateConvertLimitPlaceOrderV1Resp, Error<ConvertCreateConvertLimitPlaceOrderV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/limit/placeOrder", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let mut multipart_form_params = std::collections::HashMap::new();
if let Some(param_value) = params.base_amount {
multipart_form_params.insert("baseAmount", param_value.to_string());
}
multipart_form_params.insert("baseAsset", params.base_asset.to_string());
multipart_form_params.insert("expiredType", params.expired_type.to_string());
multipart_form_params.insert("limitPrice", params.limit_price.to_string());
if let Some(param_value) = params.quote_amount {
multipart_form_params.insert("quoteAmount", param_value.to_string());
}
multipart_form_params.insert("quoteAsset", params.quote_asset.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("side", params.side.to_string());
multipart_form_params.insert("timestamp", params.timestamp.to_string());
if let Some(param_value) = params.wallet_type {
multipart_form_params.insert("walletType", param_value.to_string());
}
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertCreateConvertLimitPlaceOrderV1Resp`"))),
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::ConvertCreateConvertLimitPlaceOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertCreateConvertLimitPlaceOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn convert_create_convert_limit_query_open_orders_v1(configuration: &configuration::Configuration, params: ConvertCreateConvertLimitQueryOpenOrdersV1Params) -> Result<models::ConvertCreateConvertLimitQueryOpenOrdersV1Resp, Error<ConvertCreateConvertLimitQueryOpenOrdersV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/limit/queryOpenOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let mut multipart_form_params = std::collections::HashMap::new();
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("timestamp", params.timestamp.to_string());
req_builder = req_builder.form(&multipart_form_params);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertCreateConvertLimitQueryOpenOrdersV1Resp`"))),
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::ConvertCreateConvertLimitQueryOpenOrdersV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertCreateConvertLimitQueryOpenOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn convert_get_convert_order_status_v1(configuration: &configuration::Configuration, params: ConvertGetConvertOrderStatusV1Params) -> Result<models::ConvertGetConvertOrderStatusV1Resp, Error<ConvertGetConvertOrderStatusV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/orderStatus", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.order_id {
query_params.push(("orderId".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.quote_id {
query_params.push(("quoteId".to_string(), param_value.to_string()));
}
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertGetConvertOrderStatusV1Resp`"))),
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::ConvertGetConvertOrderStatusV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertGetConvertOrderStatusV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn convert_get_convert_trade_flow_v1(configuration: &configuration::Configuration, params: ConvertGetConvertTradeFlowV1Params) -> Result<models::ConvertGetConvertTradeFlowV1Resp, Error<ConvertGetConvertTradeFlowV1Error>> {
let uri_str = format!("{}/sapi/v1/convert/tradeFlow", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("startTime".to_string(), params.start_time.to_string()));
query_params.push(("endTime".to_string(), params.end_time.to_string()));
if let Some(ref param_value) = params.limit {
query_params.push(("limit".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.recv_window {
query_params.push(("recvWindow".to_string(), param_value.to_string()));
}
query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConvertGetConvertTradeFlowV1Resp`"))),
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::ConvertGetConvertTradeFlowV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ConvertGetConvertTradeFlowV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}