use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::subaccount::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Clone, Debug, Default)]
pub struct SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Params {
pub email: String,
pub status: String,
pub sub_account_api_key: String,
pub timestamp: i64,
pub ip_address: Option<String>,
pub recv_window: Option<i64>
}
#[derive(Clone, Debug, Default)]
pub struct SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Params {
pub email: String,
pub sub_account_api_key: String,
pub timestamp: i64,
pub ip_address: Option<String>,
pub recv_window: Option<i64>
}
#[derive(Clone, Debug, Default)]
pub struct SubaccountGetSubAccountSubAccountApiIpRestrictionV1Params {
pub email: String,
pub sub_account_api_key: String,
pub timestamp: i64,
pub recv_window: Option<i64>
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SubaccountGetSubAccountSubAccountApiIpRestrictionV1Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
pub async fn subaccount_create_sub_account_sub_account_api_ip_restriction_v2(configuration: &configuration::Configuration, params: SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Params) -> Result<models::SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Resp, Error<SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Error>> {
let uri_str = format!("{}/sapi/v2/sub-account/subAccountApi/ipRestriction", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let mut multipart_form_params = std::collections::HashMap::new();
multipart_form_params.insert("email", params.email.to_string());
if let Some(param_value) = params.ip_address {
multipart_form_params.insert("ipAddress", 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("status", params.status.to_string());
multipart_form_params.insert("subAccountApiKey", params.sub_account_api_key.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::SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Resp`"))),
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::SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SubaccountCreateSubAccountSubAccountApiIpRestrictionV2Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn subaccount_delete_sub_account_sub_account_api_ip_restriction_ip_list_v1(configuration: &configuration::Configuration, params: SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Params) -> Result<models::SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Resp, Error<SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Error>> {
let uri_str = format!("{}/sapi/v1/sub-account/subAccountApi/ipRestriction/ipList", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("email".to_string(), params.email.to_string()));
query_params.push(("subAccountApiKey".to_string(), params.sub_account_api_key.to_string()));
if let Some(ref param_value) = params.ip_address {
query_params.push(("ipAddress".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.recv_window {
query_params.push(("recvWindow".to_string(), param_value.to_string()));
}
query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Resp`"))),
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::SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SubaccountDeleteSubAccountSubAccountApiIpRestrictionIpListV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn subaccount_get_sub_account_sub_account_api_ip_restriction_v1(configuration: &configuration::Configuration, params: SubaccountGetSubAccountSubAccountApiIpRestrictionV1Params) -> Result<models::SubaccountGetSubAccountSubAccountApiIpRestrictionV1Resp, Error<SubaccountGetSubAccountSubAccountApiIpRestrictionV1Error>> {
let uri_str = format!("{}/sapi/v1/sub-account/subAccountApi/ipRestriction", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
let mut query_params: Vec<(String, String)> = Vec::new();
query_params.push(("email".to_string(), params.email.to_string()));
query_params.push(("subAccountApiKey".to_string(), params.sub_account_api_key.to_string()));
if let Some(ref param_value) = params.recv_window {
query_params.push(("recvWindow".to_string(), param_value.to_string()));
}
query_params.push(("timestamp".to_string(), params.timestamp.to_string()));
let mut header_params = std::collections::HashMap::new();
if let Some(ref binance_auth) = configuration.binance_auth {
header_params.insert("X-MBX-APIKEY".to_string(), binance_auth.api_key().to_string());
let body_string: Option<Vec<u8>> = None;
let signature = match binance_auth.sign(Some(&query_params), body_string.as_deref()) {
Ok(sig) => sig,
Err(e) => return Err(Error::Generic(format!("Failed to sign request: {}", e))),
};
query_params.push(("signature".to_string(), signature));
}
if !query_params.is_empty() {
req_builder = req_builder.query(&query_params);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
for (header_name, header_value) in header_params {
req_builder = req_builder.header(&header_name, &header_value);
}
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::SubaccountGetSubAccountSubAccountApiIpRestrictionV1Resp`"))),
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::SubaccountGetSubAccountSubAccountApiIpRestrictionV1Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SubaccountGetSubAccountSubAccountApiIpRestrictionV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}