/*
* Binance Options API
*
* OpenAPI specification for Binance exchange - Options 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::options::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for passing parameters to the method [`options_create_countdown_cancel_all_heart_beat_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsCreateCountdownCancelAllHeartBeatV1Params {
pub timestamp: i64,
pub underlyings: String,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`options_create_countdown_cancel_all_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsCreateCountdownCancelAllV1Params {
pub countdown_time: i64,
pub timestamp: i64,
pub underlying: String,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`options_create_mmp_reset_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsCreateMmpResetV1Params {
pub timestamp: i64,
pub recv_window: Option<i64>,
pub underlying: Option<String>
}
/// struct for passing parameters to the method [`options_create_mmp_set_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsCreateMmpSetV1Params {
pub timestamp: i64,
pub delta_limit: Option<String>,
pub frozen_time_in_milliseconds: Option<i64>,
pub qty_limit: Option<String>,
pub recv_window: Option<i64>,
pub underlying: Option<String>,
pub window_time_in_milliseconds: Option<i64>
}
/// struct for passing parameters to the method [`options_get_countdown_cancel_all_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsGetCountdownCancelAllV1Params {
pub timestamp: i64,
/// Option underlying, e.g BTCUSDT
pub underlying: Option<String>,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`options_get_margin_account_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsGetMarginAccountV1Params {
pub timestamp: i64,
pub recv_window: Option<i64>
}
/// struct for passing parameters to the method [`options_get_mmp_v1`]
#[derive(Clone, Debug, Default)]
pub struct OptionsGetMmpV1Params {
pub timestamp: i64,
/// underlying, e.g BTCUSDT
pub underlying: Option<String>,
pub recv_window: Option<i64>
}
/// struct for typed errors of method [`options_create_countdown_cancel_all_heart_beat_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsCreateCountdownCancelAllHeartBeatV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`options_create_countdown_cancel_all_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsCreateCountdownCancelAllV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`options_create_mmp_reset_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsCreateMmpResetV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`options_create_mmp_set_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsCreateMmpSetV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`options_get_countdown_cancel_all_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsGetCountdownCancelAllV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`options_get_margin_account_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsGetMarginAccountV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`options_get_mmp_v1`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionsGetMmpV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// This endpoint resets the time from which the countdown will begin to the time this messaged is received. It should be called repeatedly as heartbeats. Multiple heartbeats can be updated at once by specifying the underlying symbols as a list (ex. BTCUSDT,ETHUSDT) in the underlyings parameter.
pub async fn options_create_countdown_cancel_all_heart_beat_v1(configuration: &configuration::Configuration, params: OptionsCreateCountdownCancelAllHeartBeatV1Params) -> Result<models::OptionsCreateCountdownCancelAllHeartBeatV1Resp, Error<OptionsCreateCountdownCancelAllHeartBeatV1Error>> {
let uri_str = format!("{}/eapi/v1/countdownCancelAllHeartBeat", 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.recv_window {
multipart_form_params.insert("recvWindow", param_value.to_string());
}
multipart_form_params.insert("timestamp", params.timestamp.to_string());
multipart_form_params.insert("underlyings", params.underlyings.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::OptionsCreateCountdownCancelAllHeartBeatV1Resp`"))),
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::OptionsCreateCountdownCancelAllHeartBeatV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsCreateCountdownCancelAllHeartBeatV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// This endpoint sets the parameters of the auto-cancel feature which cancels all open orders (both market maker protection and non market maker protection order types) of the underlying symbol at the end of the specified countdown time period if no heartbeat message is sent. After the countdown time period, all open orders will be cancelled and new orders will be rejected with error code -2010 until either a heartbeat message is sent or the auto-cancel feature is turned off by setting countdownTime to 0.
pub async fn options_create_countdown_cancel_all_v1(configuration: &configuration::Configuration, params: OptionsCreateCountdownCancelAllV1Params) -> Result<models::OptionsCreateCountdownCancelAllV1Resp, Error<OptionsCreateCountdownCancelAllV1Error>> {
let uri_str = format!("{}/eapi/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("timestamp", params.timestamp.to_string());
multipart_form_params.insert("underlying", params.underlying.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::OptionsCreateCountdownCancelAllV1Resp`"))),
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::OptionsCreateCountdownCancelAllV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsCreateCountdownCancelAllV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Reset MMP, start MMP order again.
pub async fn options_create_mmp_reset_v1(configuration: &configuration::Configuration, params: OptionsCreateMmpResetV1Params) -> Result<models::OptionsCreateMmpResetV1Resp, Error<OptionsCreateMmpResetV1Error>> {
let uri_str = format!("{}/eapi/v1/mmpReset", 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.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.underlying {
multipart_form_params.insert("underlying", 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::OptionsCreateMmpResetV1Resp`"))),
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::OptionsCreateMmpResetV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsCreateMmpResetV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Set config for MMP. Market Maker Protection(MMP) is a set of protection mechanism for option market maker, this mechanism is able to prevent mass trading in short period time. Once market maker's account branches the threshold, the Market Maker Protection will be triggered. When Market Maker Protection triggers, all the current MMP orders will be canceled, new MMP orders will be rejected. Market maker can use this time to reevaluate market and modify order price.
pub async fn options_create_mmp_set_v1(configuration: &configuration::Configuration, params: OptionsCreateMmpSetV1Params) -> Result<models::OptionsCreateMmpSetV1Resp, Error<OptionsCreateMmpSetV1Error>> {
let uri_str = format!("{}/eapi/v1/mmpSet", 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.delta_limit {
multipart_form_params.insert("deltaLimit", param_value.to_string());
}
if let Some(param_value) = params.frozen_time_in_milliseconds {
multipart_form_params.insert("frozenTimeInMilliseconds", param_value.to_string());
}
if let Some(param_value) = params.qty_limit {
multipart_form_params.insert("qtyLimit", 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("timestamp", params.timestamp.to_string());
if let Some(param_value) = params.underlying {
multipart_form_params.insert("underlying", param_value.to_string());
}
if let Some(param_value) = params.window_time_in_milliseconds {
multipart_form_params.insert("windowTimeInMilliseconds", 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::OptionsCreateMmpSetV1Resp`"))),
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::OptionsCreateMmpSetV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsCreateMmpSetV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// This endpoint returns the auto-cancel parameters for each underlying symbol. Note only active auto-cancel parameters will be returned, if countdownTime is set to 0 (ie. countdownTime has been turned off), the underlying symbol and corresponding countdownTime parameter will not be returned in the response.
pub async fn options_get_countdown_cancel_all_v1(configuration: &configuration::Configuration, params: OptionsGetCountdownCancelAllV1Params) -> Result<models::OptionsGetCountdownCancelAllV1Resp, Error<OptionsGetCountdownCancelAllV1Error>> {
let uri_str = format!("{}/eapi/v1/countdownCancelAll", 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.underlying {
query_params.push(("underlying".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::OptionsGetCountdownCancelAllV1Resp`"))),
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::OptionsGetCountdownCancelAllV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsGetCountdownCancelAllV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get current account information.
pub async fn options_get_margin_account_v1(configuration: &configuration::Configuration, params: OptionsGetMarginAccountV1Params) -> Result<models::OptionsGetMarginAccountV1Resp, Error<OptionsGetMarginAccountV1Error>> {
let uri_str = format!("{}/eapi/v1/marginAccount", 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.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::OptionsGetMarginAccountV1Resp`"))),
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::OptionsGetMarginAccountV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsGetMarginAccountV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get config for MMP.
pub async fn options_get_mmp_v1(configuration: &configuration::Configuration, params: OptionsGetMmpV1Params) -> Result<models::OptionsGetMmpV1Resp, Error<OptionsGetMmpV1Error>> {
let uri_str = format!("{}/eapi/v1/mmp", 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.underlying {
query_params.push(("underlying".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::OptionsGetMmpV1Resp`"))),
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::OptionsGetMmpV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<OptionsGetMmpV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}