/*
* Binance Spot API
*
* OpenAPI specification for Binance exchange - Spot 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::spot::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for passing parameters to the method [`spot_get_agg_trades_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetAggTradesV3Params {
pub symbol: String,
/// ID to get aggregate trades from INCLUSIVE.
pub from_id: Option<i64>,
/// Timestamp in ms to get aggregate trades from INCLUSIVE.
pub start_time: Option<i64>,
/// Timestamp in ms to get aggregate trades until INCLUSIVE.
pub end_time: Option<i64>,
/// Default 500; max 1000.
pub limit: Option<i32>
}
/// struct for passing parameters to the method [`spot_get_avg_price_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetAvgPriceV3Params {
pub symbol: String
}
/// struct for passing parameters to the method [`spot_get_depth_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetDepthV3Params {
pub symbol: String,
/// Default 100; max 5000. <br/> If limit > 5000. then the response will truncate to 5000.
pub limit: Option<i32>
}
/// struct for passing parameters to the method [`spot_get_historical_trades_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetHistoricalTradesV3Params {
pub symbol: String,
/// Default 500; max 1000.
pub limit: Option<i32>,
/// TradeId to fetch from. Default gets most recent trades.
pub from_id: Option<i64>
}
/// struct for passing parameters to the method [`spot_get_klines_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetKlinesV3Params {
pub symbol: String,
pub interval: String,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
/// Default: 0 (UTC)
pub time_zone: Option<String>,
/// Default 500; max 1000.
pub limit: Option<i32>
}
/// struct for passing parameters to the method [`spot_get_ticker24hr_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetTicker24hrV3Params {
/// Parameter symbol and symbols cannot be used in combination. <br/> If neither parameter is sent, tickers for all symbols will be returned in an array. <br/><br/> Examples of accepted format for the symbols parameter: ["BTCUSDT","BNBUSDT"] <br/> or <br/> %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
pub symbol: Option<String>,
/// Parameter symbol and symbols cannot be used in combination. <br/> If neither parameter is sent, tickers for all symbols will be returned in an array. <br/><br/> Examples of accepted format for the symbols parameter: ["BTCUSDT","BNBUSDT"] <br/> or <br/> %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
pub symbols: Option<String>,
/// Supported values: `FULL` or `MINI`. <br/>If none provided, the default is `FULL`
pub r#type: Option<String>
}
/// struct for passing parameters to the method [`spot_get_ticker_book_ticker_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetTickerBookTickerV3Params {
/// Parameter symbol and symbols cannot be used in combination. <br/> If neither parameter is sent, bookTickers for all symbols will be returned in an array. <br/><br/> Examples of accepted format for the symbols parameter: ["BTCUSDT","BNBUSDT"] <br/> or <br/> %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
pub symbol: Option<String>,
/// Parameter symbol and symbols cannot be used in combination. <br/> If neither parameter is sent, bookTickers for all symbols will be returned in an array. <br/><br/> Examples of accepted format for the symbols parameter: ["BTCUSDT","BNBUSDT"] <br/> or <br/> %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
pub symbols: Option<String>
}
/// struct for passing parameters to the method [`spot_get_ticker_price_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetTickerPriceV3Params {
/// Parameter symbol and symbols cannot be used in combination. <br/> If neither parameter is sent, prices for all symbols will be returned in an array. <br/><br/> Examples of accepted format for the symbols parameter: ["BTCUSDT","BNBUSDT"] <br/> or <br/> %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
pub symbol: Option<String>,
/// Parameter symbol and symbols cannot be used in combination. <br/> If neither parameter is sent, prices for all symbols will be returned in an array. <br/><br/> Examples of accepted format for the symbols parameter: ["BTCUSDT","BNBUSDT"] <br/> or <br/> %5B%22BTCUSDT%22,%22BNBUSDT%22%5D
pub symbols: Option<String>
}
/// struct for passing parameters to the method [`spot_get_ticker_trading_day_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetTickerTradingDayV3Params {
/// Either `symbol` or `symbols` must be provided <br/><br/> Examples of accepted format for the `symbols` parameter: <br/> ["BTCUSDT","BNBUSDT"] <br/>or <br/>%5B%22BTCUSDT%22,%22BNBUSDT%22%5D <br/><br/> The maximum number of `symbols` allowed in a request is 100.
pub symbol: String,
/// Either `symbol` or `symbols` must be provided <br/><br/> Examples of accepted format for the `symbols` parameter: <br/> ["BTCUSDT","BNBUSDT"] <br/>or <br/>%5B%22BTCUSDT%22,%22BNBUSDT%22%5D <br/><br/> The maximum number of `symbols` allowed in a request is 100.
pub symbols: String,
/// Default: 0 (UTC)
pub time_zone: Option<String>,
/// Supported values: `FULL` or `MINI`. <br/>If none provided, the default is `FULL`
pub r#type: Option<String>
}
/// struct for passing parameters to the method [`spot_get_ticker_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetTickerV3Params {
/// Either `symbol` or `symbols` must be provided <br/><br/> Examples of accepted format for the `symbols` parameter: <br/> ["BTCUSDT","BNBUSDT"] <br/>or <br/>%5B%22BTCUSDT%22,%22BNBUSDT%22%5D <br/><br/> The maximum number of `symbols` allowed in a request is 100.
pub symbol: String,
/// Either `symbol` or `symbols` must be provided <br/><br/> Examples of accepted format for the `symbols` parameter: <br/> ["BTCUSDT","BNBUSDT"] <br/>or <br/>%5B%22BTCUSDT%22,%22BNBUSDT%22%5D <br/><br/> The maximum number of `symbols` allowed in a request is 100.
pub symbols: String,
/// Defaults to `1d` if no parameter provided <br/> Supported `windowSize` values: <br/> `1m`,`2m`....`59m` for minutes <br/> `1h`, `2h`....`23h` - for hours <br/> `1d`...`7d` - for days <br/><br/> Units cannot be combined (e.g. `1d2h` is not allowed)
pub window_size: Option<String>,
/// Supported values: `FULL` or `MINI`. <br/>If none provided, the default is `FULL`
pub r#type: Option<String>
}
/// struct for passing parameters to the method [`spot_get_trades_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetTradesV3Params {
pub symbol: String,
/// Default 500; max 1000.
pub limit: Option<i32>
}
/// struct for passing parameters to the method [`spot_get_ui_klines_v3`]
#[derive(Clone, Debug, Default)]
pub struct SpotGetUiKlinesV3Params {
pub symbol: String,
/// See <a href=\"/docs/binance-spot-api-docs/rest-api/market-data-endpoints#kline-intervals\">`klines`</a>
pub interval: String,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
/// Default: 0 (UTC)
pub time_zone: Option<String>,
/// Default 500; max 1000.
pub limit: Option<i32>
}
/// struct for typed errors of method [`spot_get_agg_trades_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetAggTradesV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_avg_price_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetAvgPriceV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_depth_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetDepthV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_historical_trades_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetHistoricalTradesV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_klines_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetKlinesV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_ticker24hr_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetTicker24hrV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_ticker_book_ticker_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetTickerBookTickerV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_ticker_price_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetTickerPriceV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_ticker_trading_day_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetTickerTradingDayV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_ticker_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetTickerV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_trades_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetTradesV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`spot_get_ui_klines_v3`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpotGetUiKlinesV3Error {
Status4XX(models::ApiError),
Status5XX(models::ApiError),
UnknownValue(serde_json::Value),
}
/// Get compressed, aggregate trades. Trades that fill at the time, from the same taker order, with the same price will have the quantity aggregated.
pub async fn spot_get_agg_trades_v3(configuration: &configuration::Configuration, params: SpotGetAggTradesV3Params) -> Result<Vec<models::SpotGetAggTradesV3RespItem>, Error<SpotGetAggTradesV3Error>> {
let uri_str = format!("{}/api/v3/aggTrades", 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.from_id {
query_params.push(("fromId".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()));
}
// 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::SpotGetAggTradesV3RespItem>`"))),
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::SpotGetAggTradesV3RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetAggTradesV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Current average price for a symbol.
pub async fn spot_get_avg_price_v3(configuration: &configuration::Configuration, params: SpotGetAvgPriceV3Params) -> Result<models::SpotGetAvgPriceV3Resp, Error<SpotGetAvgPriceV3Error>> {
let uri_str = format!("{}/api/v3/avgPrice", 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()));
// 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::SpotGetAvgPriceV3Resp`"))),
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::SpotGetAvgPriceV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetAvgPriceV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn spot_get_depth_v3(configuration: &configuration::Configuration, params: SpotGetDepthV3Params) -> Result<models::SpotGetDepthV3Resp, Error<SpotGetDepthV3Error>> {
let uri_str = format!("{}/api/v3/depth", 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.limit {
query_params.push(("limit".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 `models::SpotGetDepthV3Resp`"))),
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::SpotGetDepthV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetDepthV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get older trades.
pub async fn spot_get_historical_trades_v3(configuration: &configuration::Configuration, params: SpotGetHistoricalTradesV3Params) -> Result<Vec<models::SpotGetHistoricalTradesV3RespItem>, Error<SpotGetHistoricalTradesV3Error>> {
let uri_str = format!("{}/api/v3/historicalTrades", 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.limit {
query_params.push(("limit".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()));
}
// 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::SpotGetHistoricalTradesV3RespItem>`"))),
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::SpotGetHistoricalTradesV3RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetHistoricalTradesV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
pub async fn spot_get_klines_v3(configuration: &configuration::Configuration, params: SpotGetKlinesV3Params) -> Result<Vec<Vec<models::SpotGetKlinesV3200ResponseInnerInner>>, Error<SpotGetKlinesV3Error>> {
let uri_str = format!("{}/api/v3/klines", 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()));
query_params.push(("interval".to_string(), params.interval.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.time_zone {
query_params.push(("timeZone".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.limit {
query_params.push(("limit".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<Vec<models::SpotGetKlinesV3200ResponseInnerInner>>`"))),
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<Vec<models::SpotGetKlinesV3200ResponseInnerInner>>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetKlinesV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 24 hour rolling window price change statistics. Careful when accessing this with no symbol.
pub async fn spot_get_ticker24hr_v3(configuration: &configuration::Configuration, params: SpotGetTicker24hrV3Params) -> Result<models::SpotGetTicker24hrV3Resp, Error<SpotGetTicker24hrV3Error>> {
let uri_str = format!("{}/api/v3/ticker/24hr", 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.symbols {
query_params.push(("symbols".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.r#type {
query_params.push(("type".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 `models::SpotGetTicker24hrV3Resp`"))),
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::SpotGetTicker24hrV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetTicker24hrV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Best price/qty on the order book for a symbol or symbols.
pub async fn spot_get_ticker_book_ticker_v3(configuration: &configuration::Configuration, params: SpotGetTickerBookTickerV3Params) -> Result<models::SpotGetTickerBookTickerV3Resp, Error<SpotGetTickerBookTickerV3Error>> {
let uri_str = format!("{}/api/v3/ticker/bookTicker", 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.symbols {
query_params.push(("symbols".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 `models::SpotGetTickerBookTickerV3Resp`"))),
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::SpotGetTickerBookTickerV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetTickerBookTickerV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Latest price for a symbol or symbols.
pub async fn spot_get_ticker_price_v3(configuration: &configuration::Configuration, params: SpotGetTickerPriceV3Params) -> Result<models::SpotGetTickerPriceV3Resp, Error<SpotGetTickerPriceV3Error>> {
let uri_str = format!("{}/api/v3/ticker/price", 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.symbols {
query_params.push(("symbols".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 `models::SpotGetTickerPriceV3Resp`"))),
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::SpotGetTickerPriceV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetTickerPriceV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Price change statistics for a trading day. 4 for each requested symbol. The weight for this request will cap at 200 once the number of symbols in the request is more than 50.
pub async fn spot_get_ticker_trading_day_v3(configuration: &configuration::Configuration, params: SpotGetTickerTradingDayV3Params) -> Result<models::SpotGetTickerTradingDayV3Resp, Error<SpotGetTickerTradingDayV3Error>> {
let uri_str = format!("{}/api/v3/ticker/tradingDay", 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()));
query_params.push(("symbols".to_string(), params.symbols.to_string()));
if let Some(ref param_value) = params.time_zone {
query_params.push(("timeZone".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.r#type {
query_params.push(("type".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 `models::SpotGetTickerTradingDayV3Resp`"))),
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::SpotGetTickerTradingDayV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetTickerTradingDayV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Note: This endpoint is different from the GET /api/v3/ticker/24hr endpoint. The window used to compute statistics will be no more than 59999ms from the requested windowSize. openTime for /api/v3/ticker always starts on a minute, while the closeTime is the current time of the request. As such, the effective window will be up to 59999ms wider than windowSize. E.g. If the closeTime is 1641287867099 (January 04, 2022 09:17:47:099 UTC) , and the windowSize is 1d. the openTime will be: 1641201420000 (January 3, 2022, 09:17:00) 4 for each requested symbol regardless of windowSize. The weight for this request will cap at 200 once the number of symbols in the request is more than 50.
pub async fn spot_get_ticker_v3(configuration: &configuration::Configuration, params: SpotGetTickerV3Params) -> Result<models::SpotGetTickerV3Resp, Error<SpotGetTickerV3Error>> {
let uri_str = format!("{}/api/v3/ticker", 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()));
query_params.push(("symbols".to_string(), params.symbols.to_string()));
if let Some(ref param_value) = params.window_size {
query_params.push(("windowSize".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.r#type {
query_params.push(("type".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 `models::SpotGetTickerV3Resp`"))),
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::SpotGetTickerV3Resp`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetTickerV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Get recent trades.
pub async fn spot_get_trades_v3(configuration: &configuration::Configuration, params: SpotGetTradesV3Params) -> Result<Vec<models::SpotGetTradesV3RespItem>, Error<SpotGetTradesV3Error>> {
let uri_str = format!("{}/api/v3/trades", 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.limit {
query_params.push(("limit".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::SpotGetTradesV3RespItem>`"))),
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::SpotGetTradesV3RespItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetTradesV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// The request is similar to klines having the same parameters and response. uiKlines return modified kline data, optimized for presentation of candlestick charts.
pub async fn spot_get_ui_klines_v3(configuration: &configuration::Configuration, params: SpotGetUiKlinesV3Params) -> Result<Vec<Vec<models::SpotGetKlinesV3200ResponseInnerInner>>, Error<SpotGetUiKlinesV3Error>> {
let uri_str = format!("{}/api/v3/uiKlines", 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()));
query_params.push(("interval".to_string(), params.interval.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.time_zone {
query_params.push(("timeZone".to_string(), param_value.to_string()));
}
if let Some(ref param_value) = params.limit {
query_params.push(("limit".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<Vec<models::SpotGetKlinesV3200ResponseInnerInner>>`"))),
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<Vec<models::SpotGetKlinesV3200ResponseInnerInner>>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SpotGetUiKlinesV3Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}