/*
* Binance COIN-M Futures API
*
* OpenAPI specification for Binance exchange - Cmfutures API
*
* The version of the OpenAPI document: 0.1.0
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::derivatives::cmfutures::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for passing parameters to the method [`cmfutures_create_batch_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreateBatchOrdersV1Params {
pub batch_orders: Vec<models::CmfuturesCreateBatchOrderV1ReqBatchOrdersItem>,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_create_countdown_cancel_all_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreateCountdownCancelAllV1Params {
pub countdown_time: i64,
pub symbol: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_create_leverage_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreateLeverageV1Params {
pub leverage: i32,
pub symbol: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_create_margin_type_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreateMarginTypeV1Params {
pub margin_type: String,
pub symbol: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_create_order_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreateOrderV1Params {
pub side: String,
pub symbol: String,
pub timestamp: i64,
pub r#type: String,
pub activation_price: Option<String>,
pub callback_rate: Option<String>,
pub close_position: Option<String>,
pub new_client_order_id: Option<String>,
pub new_order_resp_type: Option<String>,
pub position_side: Option<String>,
pub price: Option<String>,
pub price_match: Option<String>,
pub price_protect: Option<String>,
pub quantity: Option<String>,
pub recv_window: Option<i64>,
pub reduce_only: Option<String>,
pub self_trade_prevention_mode: Option<String>,
pub stop_price: Option<String>,
pub time_in_force: Option<String>,
pub working_type: Option<String>
}
/// struct for passing parameters to the method [`cmfutures_create_position_margin_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreatePositionMarginV1Params {
pub amount: String,
pub symbol: String,
pub timestamp: i64,
pub r#type: i32,
pub position_side: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_create_position_side_dual_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesCreatePositionSideDualV1Params {
pub dual_side_position: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_delete_all_open_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesDeleteAllOpenOrdersV1Params {
pub symbol: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_delete_batch_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesDeleteBatchOrdersV1Params {
pub symbol: String,
pub timestamp: i64,
/// max length 10 <br/> e.g. [1234567,2345678]
pub order_id_list: Option<Vec<i64>>,
/// max length 10<br/> e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma.
pub orig_client_order_id_list: Option<Vec<String>>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_delete_order_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesDeleteOrderV1Params {
pub symbol: String,
pub timestamp: i64,
pub order_id: Option<i64>,
pub orig_client_order_id: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_adl_quantile_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetAdlQuantileV1Params {
pub timestamp: i64,
pub symbol: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_all_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetAllOrdersV1Params {
pub timestamp: i64,
pub symbol: Option<String>,
pub pair: Option<String>,
pub order_id: Option<i64>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
/// Default 50; max 100.
pub limit: Option<i32>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_force_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetForceOrdersV1Params {
pub timestamp: i64,
pub symbol: Option<String>,
pub auto_close_type: Option<String>,
pub recv_window: Option<i64>,
pub limit: Option<i32>,
pub start_time: Option<i64>,
pub end_time: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_open_order_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetOpenOrderV1Params {
pub symbol: String,
pub timestamp: i64,
pub order_id: Option<i64>,
pub orig_client_order_id: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_open_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetOpenOrdersV1Params {
pub timestamp: i64,
pub symbol: Option<String>,
pub pair: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_order_amendment_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetOrderAmendmentV1Params {
pub symbol: String,
pub timestamp: i64,
pub order_id: Option<i64>,
pub orig_client_order_id: Option<String>,
/// Timestamp in ms to get modification history from INCLUSIVE
pub start_time: Option<i64>,
/// Timestamp in ms to get modification history until INCLUSIVE
pub end_time: Option<i64>,
/// Default 50; max 100
pub limit: Option<i32>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_order_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetOrderV1Params {
pub symbol: String,
pub timestamp: i64,
pub order_id: Option<i64>,
pub orig_client_order_id: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_position_margin_history_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetPositionMarginHistoryV1Params {
pub symbol: String,
pub timestamp: i64,
/// 1: Add position margin,2: Reduce position margin
pub r#type: Option<i32>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
/// Default: 50
pub limit: Option<i32>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_position_risk_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetPositionRiskV1Params {
pub timestamp: i64,
pub margin_asset: Option<String>,
pub pair: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_get_user_trades_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesGetUserTradesV1Params {
pub timestamp: i64,
pub symbol: Option<String>,
pub pair: Option<String>,
pub order_id: Option<String>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
/// Trade id to fetch from. Default gets most recent trades.
pub from_id: Option<i64>,
/// Default 50; max 1000
pub limit: Option<i32>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_update_batch_orders_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesUpdateBatchOrdersV1Params {
pub batch_orders: Vec<models::CmfuturesUpdateBatchOrdersV1ReqBatchOrdersItem>,
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`cmfutures_update_order_v1`]
#[derive(Clone, Debug, Default)]
pub struct CmfuturesUpdateOrderV1Params {
pub side: String,
pub symbol: String,
pub timestamp: i64,
pub order_id: Option<i64>,
pub orig_client_order_id: Option<String>,
pub price: Option<String>,
pub price_match: Option<String>,
pub quantity: Option<String>,
pub recv_window: Option<i64>
}
/// struct for typed errors of method [`cmfutures_create_batch_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreateBatchOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_create_countdown_cancel_all_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreateCountdownCancelAllV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_create_leverage_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreateLeverageV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_create_margin_type_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreateMarginTypeV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_create_order_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreateOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_create_position_margin_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreatePositionMarginV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_create_position_side_dual_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesCreatePositionSideDualV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_delete_all_open_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesDeleteAllOpenOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_delete_batch_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesDeleteBatchOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_delete_order_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesDeleteOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_adl_quantile_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetAdlQuantileV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_all_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetAllOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_force_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetForceOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_open_order_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetOpenOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_open_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetOpenOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_order_amendment_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetOrderAmendmentV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_order_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_position_margin_history_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetPositionMarginHistoryV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_position_risk_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetPositionRiskV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_get_user_trades_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesGetUserTradesV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_update_batch_orders_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesUpdateBatchOrdersV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`cmfutures_update_order_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CmfuturesUpdateOrderV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// Place multiple orders
pub async fn cmfutures_create_batch_orders_v1(configuration: &configuration::Configuration, params: CmfuturesCreateBatchOrdersV1Params) -> Result<Vec<models::CmfuturesCreateBatchOrdersV1RespInner>, Error<CmfuturesCreateBatchOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/batchOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("batchOrders", params.batch_orders.into_iter().map(|p| serde_json::to_string(&p).unwrap_or_default()).collect::<Vec<String>>().join(",").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 `Vec<models::CmfuturesCreateBatchOrdersV1RespInner>`"))),
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::CmfuturesCreateBatchOrdersV1RespInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreateBatchOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Cancel all open orders of the specified symbol at the end of the specified countdown. This rest endpoint means to ensure your open orders are canceled in case of an outage. The endpoint should be called repeatedly as heartbeats so that the existing countdown time can be canceled and repalced by a new one. The system will check all countdowns approximately every 10 milliseconds, so please note that sufficient redundancy should be considered when using this function. We do not recommend setting the countdown time to be too precise or too small.
pub async fn cmfutures_create_countdown_cancel_all_v1(configuration: &configuration::Configuration, params: CmfuturesCreateCountdownCancelAllV1Params) -> Result<models::CmfuturesCreateCountdownCancelAllV1Resp, Error<CmfuturesCreateCountdownCancelAllV1Error>> {
let uri_str = format!("{}/dapi/v1/countdownCancelAll", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("countdownTime", params.countdown_time.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("symbol", params.symbol.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::CmfuturesCreateCountdownCancelAllV1Resp`"))),
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::CmfuturesCreateCountdownCancelAllV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreateCountdownCancelAllV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Change user's initial leverage in the specific symbol market. For Hedge Mode, LONG and SHORT positions of one symbol use the same initial leverage and share a total notional value.
pub async fn cmfutures_create_leverage_v1(configuration: &configuration::Configuration, params: CmfuturesCreateLeverageV1Params) -> Result<models::CmfuturesCreateLeverageV1Resp, Error<CmfuturesCreateLeverageV1Error>> {
let uri_str = format!("{}/dapi/v1/leverage", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("leverage", params.leverage.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("symbol", params.symbol.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::CmfuturesCreateLeverageV1Resp`"))),
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::CmfuturesCreateLeverageV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreateLeverageV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Change user's margin type in the specific symbol market.For Hedge Mode, LONG and SHORT positions of one symbol use the same margin type. With ISOLATED margin type, margins of the LONG and SHORT positions are isolated from each other.
pub async fn cmfutures_create_margin_type_v1(configuration: &configuration::Configuration, params: CmfuturesCreateMarginTypeV1Params) -> Result<models::CmfuturesCreateMarginTypeV1Resp, Error<CmfuturesCreateMarginTypeV1Error>> {
let uri_str = format!("{}/dapi/v1/marginType", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("marginType", params.margin_type.to_string());
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("symbol", params.symbol.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::CmfuturesCreateMarginTypeV1Resp`"))),
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::CmfuturesCreateMarginTypeV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreateMarginTypeV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Send in a new order.
pub async fn cmfutures_create_order_v1(configuration: &configuration::Configuration, params: CmfuturesCreateOrderV1Params) -> Result<models::CmfuturesCreateOrderV1Resp, Error<CmfuturesCreateOrderV1Error>> {
let uri_str = format!("{}/dapi/v1/order", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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.activation_price {
multipart_form_params.insert("activationPrice", param_value.to_string());
}
if let Some(param_value) = params.callback_rate {
multipart_form_params.insert("callbackRate", param_value.to_string());
}
if let Some(param_value) = params.close_position {
multipart_form_params.insert("closePosition", param_value.to_string());
}
if let Some(param_value) = params.new_client_order_id {
multipart_form_params.insert("newClientOrderId", param_value.to_string());
}
if let Some(param_value) = params.new_order_resp_type {
multipart_form_params.insert("newOrderRespType", param_value.to_string());
}
if let Some(param_value) = params.position_side {
multipart_form_params.insert("positionSide", param_value.to_string());
}
if let Some(param_value) = params.price {
multipart_form_params.insert("price", param_value.to_string());
}
if let Some(param_value) = params.price_match {
multipart_form_params.insert("priceMatch", param_value.to_string());
}
if let Some(param_value) = params.price_protect {
multipart_form_params.insert("priceProtect", param_value.to_string());
}
if let Some(param_value) = params.quantity {
multipart_form_params.insert("quantity", param_value.to_string());
}
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
if let Some(param_value) = params.reduce_only {
multipart_form_params.insert("reduceOnly", param_value.to_string());
}
if let Some(param_value) = params.self_trade_prevention_mode {
multipart_form_params.insert("selfTradePreventionMode", param_value.to_string());
}
multipart_form_params.insert("side", params.side.to_string());
if let Some(param_value) = params.stop_price {
multipart_form_params.insert("stopPrice", param_value.to_string());
}
multipart_form_params.insert("symbol", params.symbol.to_string());
if let Some(param_value) = params.time_in_force {
multipart_form_params.insert("timeInForce", param_value.to_string());
}
multipart_form_params.insert("timestamp", params.timestamp.to_string());
multipart_form_params.insert("type", params.r#type.to_string());
if let Some(param_value) = params.working_type {
multipart_form_params.insert("workingType", 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::CmfuturesCreateOrderV1Resp`"))),
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::CmfuturesCreateOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreateOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Modify Isolated Position Margin
pub async fn cmfutures_create_position_margin_v1(configuration: &configuration::Configuration, params: CmfuturesCreatePositionMarginV1Params) -> Result<models::CmfuturesCreatePositionMarginV1Resp, Error<CmfuturesCreatePositionMarginV1Error>> {
let uri_str = format!("{}/dapi/v1/positionMargin", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("amount", params.amount.to_string());
if let Some(param_value) = params.position_side {
multipart_form_params.insert("positionSide", param_value.to_string());
}
if let Some(param_value) = params.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("symbol", params.symbol.to_string());
multipart_form_params.insert("timestamp", params.timestamp.to_string());
multipart_form_params.insert("type", params.r#type.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::CmfuturesCreatePositionMarginV1Resp`"))),
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::CmfuturesCreatePositionMarginV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreatePositionMarginV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Change user's position mode (Hedge Mode or One-way Mode ) on EVERY symbol
pub async fn cmfutures_create_position_side_dual_v1(configuration: &configuration::Configuration, params: CmfuturesCreatePositionSideDualV1Params) -> Result<models::CmfuturesCreatePositionSideDualV1Resp, Error<CmfuturesCreatePositionSideDualV1Error>> {
let uri_str = format!("{}/dapi/v1/positionSide/dual", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("dualSidePosition", params.dual_side_position.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::CmfuturesCreatePositionSideDualV1Resp`"))),
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::CmfuturesCreatePositionSideDualV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesCreatePositionSideDualV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Cancel All Open Orders
pub async fn cmfutures_delete_all_open_orders_v1(configuration: &configuration::Configuration, params: CmfuturesDeleteAllOpenOrdersV1Params) -> Result<models::CmfuturesDeleteAllOpenOrdersV1Resp, Error<CmfuturesDeleteAllOpenOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/allOpenOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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::CmfuturesDeleteAllOpenOrdersV1Resp`"))),
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::CmfuturesDeleteAllOpenOrdersV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesDeleteAllOpenOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Cancel Multiple Orders
pub async fn cmfutures_delete_batch_orders_v1(configuration: &configuration::Configuration, params: CmfuturesDeleteBatchOrdersV1Params) -> Result<Vec<models::CmfuturesDeleteBatchOrdersV1RespInner>, Error<CmfuturesDeleteBatchOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/batchOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.to_string()));
if let Some(ref param_value) = params.order_id_list {
match "multi" {
"multi" => {
for p in param_value {
query_params.push(("orderIdList".to_string(), p.to_string()));
}
},
_ => {
let joined = param_value.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",");
query_params.push(("orderIdList".to_string(), joined));
}
};
}
if let Some(ref param_value) = params.orig_client_order_id_list {
match "multi" {
"multi" => {
for p in param_value {
query_params.push(("origClientOrderIdList".to_string(), p.to_string()));
}
},
_ => {
let joined = param_value.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",");
query_params.push(("origClientOrderIdList".to_string(), joined));
}
};
}
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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesDeleteBatchOrdersV1RespInner>`"))),
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::CmfuturesDeleteBatchOrdersV1RespInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesDeleteBatchOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Cancel an active order.
pub async fn cmfutures_delete_order_v1(configuration: &configuration::Configuration, params: CmfuturesDeleteOrderV1Params) -> Result<models::CmfuturesDeleteOrderV1Resp, Error<CmfuturesDeleteOrderV1Error>> {
let uri_str = format!("{}/dapi/v1/order", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.to_string()));
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.orig_client_order_id {
query_params.push(("origClientOrderId".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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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::CmfuturesDeleteOrderV1Resp`"))),
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::CmfuturesDeleteOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesDeleteOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Query position ADL quantile estimation
pub async fn cmfutures_get_adl_quantile_v1(configuration: &configuration::Configuration, params: CmfuturesGetAdlQuantileV1Params) -> Result<Vec<models::CmfuturesGetAdlQuantileV1RespItem>, Error<CmfuturesGetAdlQuantileV1Error>> {
let uri_str = format!("{}/dapi/v1/adlQuantile", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.symbol {
query_params.push(("symbol".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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetAdlQuantileV1RespItem>`"))),
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::CmfuturesGetAdlQuantileV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetAdlQuantileV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get all account orders; active, canceled, or filled.
pub async fn cmfutures_get_all_orders_v1(configuration: &configuration::Configuration, params: CmfuturesGetAllOrdersV1Params) -> Result<Vec<models::CmfuturesGetAllOrdersV1RespItem>, Error<CmfuturesGetAllOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/allOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.symbol {
query_params.push(("symbol".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.pair {
query_params.push(("pair".to_string(), param_value.to_string()));
}
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.start_time {
query_params.push(("startTime".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.end_time {
query_params.push(("endTime".to_string(), param_value.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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetAllOrdersV1RespItem>`"))),
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::CmfuturesGetAllOrdersV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetAllOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// User's Force Orders
pub async fn cmfutures_get_force_orders_v1(configuration: &configuration::Configuration, params: CmfuturesGetForceOrdersV1Params) -> Result<Vec<models::CmfuturesGetForceOrdersV1RespItem>, Error<CmfuturesGetForceOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/forceOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.symbol {
query_params.push(("symbol".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.auto_close_type {
query_params.push(("autoCloseType".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()));
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.start_time {
query_params.push(("startTime".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.end_time {
query_params.push(("endTime".to_string(), param_value.to_string()));
}
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetForceOrdersV1RespItem>`"))),
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::CmfuturesGetForceOrdersV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetForceOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Query Current Open Order
pub async fn cmfutures_get_open_order_v1(configuration: &configuration::Configuration, params: CmfuturesGetOpenOrderV1Params) -> Result<models::CmfuturesGetOpenOrderV1Resp, Error<CmfuturesGetOpenOrderV1Error>> {
let uri_str = format!("{}/dapi/v1/openOrder", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.to_string()));
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.orig_client_order_id {
query_params.push(("origClientOrderId".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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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::CmfuturesGetOpenOrderV1Resp`"))),
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::CmfuturesGetOpenOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetOpenOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get all open orders on a symbol. Careful when accessing this with no symbol.
pub async fn cmfutures_get_open_orders_v1(configuration: &configuration::Configuration, params: CmfuturesGetOpenOrdersV1Params) -> Result<Vec<models::CmfuturesGetOpenOrdersV1RespItem>, Error<CmfuturesGetOpenOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/openOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.symbol {
query_params.push(("symbol".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.pair {
query_params.push(("pair".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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetOpenOrdersV1RespItem>`"))),
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::CmfuturesGetOpenOrdersV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetOpenOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get order modification history
pub async fn cmfutures_get_order_amendment_v1(configuration: &configuration::Configuration, params: CmfuturesGetOrderAmendmentV1Params) -> Result<Vec<models::CmfuturesGetOrderAmendmentV1RespItem>, Error<CmfuturesGetOrderAmendmentV1Error>> {
let uri_str = format!("{}/dapi/v1/orderAmendment", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.to_string()));
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.orig_client_order_id {
query_params.push(("origClientOrderId".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.start_time {
query_params.push(("startTime".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.end_time {
query_params.push(("endTime".to_string(), param_value.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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetOrderAmendmentV1RespItem>`"))),
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::CmfuturesGetOrderAmendmentV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetOrderAmendmentV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Check an order's status.
pub async fn cmfutures_get_order_v1(configuration: &configuration::Configuration, params: CmfuturesGetOrderV1Params) -> Result<models::CmfuturesGetOrderV1Resp, Error<CmfuturesGetOrderV1Error>> {
let uri_str = format!("{}/dapi/v1/order", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.to_string()));
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.orig_client_order_id {
query_params.push(("origClientOrderId".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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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::CmfuturesGetOrderV1Resp`"))),
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::CmfuturesGetOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get position margin change history
pub async fn cmfutures_get_position_margin_history_v1(configuration: &configuration::Configuration, params: CmfuturesGetPositionMarginHistoryV1Params) -> Result<Vec<models::CmfuturesGetPositionMarginHistoryV1RespItem>, Error<CmfuturesGetPositionMarginHistoryV1Error>> {
let uri_str = format!("{}/dapi/v1/positionMargin/history", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("symbol".to_string(), params.symbol.to_string()));
if let Some(ref param_value) = params.r#type {
query_params.push(("type".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.start_time {
query_params.push(("startTime".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.end_time {
query_params.push(("endTime".to_string(), param_value.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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetPositionMarginHistoryV1RespItem>`"))),
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::CmfuturesGetPositionMarginHistoryV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetPositionMarginHistoryV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get current account information.
pub async fn cmfutures_get_position_risk_v1(configuration: &configuration::Configuration, params: CmfuturesGetPositionRiskV1Params) -> Result<Vec<models::CmfuturesGetPositionRiskV1RespItem>, Error<CmfuturesGetPositionRiskV1Error>> {
let uri_str = format!("{}/dapi/v1/positionRisk", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.margin_asset {
query_params.push(("marginAsset".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.pair {
query_params.push(("pair".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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetPositionRiskV1RespItem>`"))),
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::CmfuturesGetPositionRiskV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetPositionRiskV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get trades for a specific account and symbol.
pub async fn cmfutures_get_user_trades_v1(configuration: &configuration::Configuration, params: CmfuturesGetUserTradesV1Params) -> Result<Vec<models::CmfuturesGetUserTradesV1RespItem>, Error<CmfuturesGetUserTradesV1Error>> {
let uri_str = format!("{}/dapi/v1/userTrades", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
if let Some(ref param_value) = params.symbol {
query_params.push(("symbol".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.pair {
query_params.push(("pair".to_string(), param_value.to_string()));
}
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.start_time {
query_params.push(("startTime".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.end_time {
query_params.push(("endTime".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.from_id {
query_params.push(("fromId".to_string(), param_value.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()));
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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 `Vec<models::CmfuturesGetUserTradesV1RespItem>`"))),
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::CmfuturesGetUserTradesV1RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesGetUserTradesV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Modify Multiple Orders
pub async fn cmfutures_update_batch_orders_v1(configuration: &configuration::Configuration, params: CmfuturesUpdateBatchOrdersV1Params) -> Result<Vec<models::CmfuturesUpdateBatchOrdersV1RespInner>, Error<CmfuturesUpdateBatchOrdersV1Error>> {
let uri_str = format!("{}/dapi/v1/batchOrders", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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("batchOrders", params.batch_orders.into_iter().map(|p| serde_json::to_string(&p).unwrap_or_default()).collect::<Vec<String>>().join(",").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 `Vec<models::CmfuturesUpdateBatchOrdersV1RespInner>`"))),
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::CmfuturesUpdateBatchOrdersV1RespInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesUpdateBatchOrdersV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Order modify function, currently only LIMIT order modification is supported, modified orders will be reordered in the match queue
pub async fn cmfutures_update_order_v1(configuration: &configuration::Configuration, params: CmfuturesUpdateOrderV1Params) -> Result<models::CmfuturesUpdateOrderV1Resp, Error<CmfuturesUpdateOrderV1Error>> {
let uri_str = format!("{}/dapi/v1/order", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
// Create a mutable vector for query parameters
let mut query_params: Vec<(String, String)> = Vec::new();
// Create header parameters collection
let mut header_params = std::collections::HashMap::new();
// Handle Binance Auth first if configured
if let Some(ref binance_auth) = configuration.binance_auth {
// Add API key to headers
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
// Generate request body for signing (if any)
let body_string: Option<Vec<u8>> = None;
// Sign the request
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))),
};
// Add signature to query params
query_params.push(("signature".to_string(), signature));
}
// Apply all query parameters
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
// Add user agent if configured
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
// Apply all header parameters
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.order_id {
multipart_form_params.insert("orderId", param_value.to_string());
}
if let Some(param_value) = params.orig_client_order_id {
multipart_form_params.insert("origClientOrderId", param_value.to_string());
}
if let Some(param_value) = params.price {
multipart_form_params.insert("price", param_value.to_string());
}
if let Some(param_value) = params.price_match {
multipart_form_params.insert("priceMatch", param_value.to_string());
}
if let Some(param_value) = params.quantity {
multipart_form_params.insert("quantity", param_value.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("symbol", params.symbol.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::CmfuturesUpdateOrderV1Resp`"))),
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::CmfuturesUpdateOrderV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<CmfuturesUpdateOrderV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}