use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Clone, Debug, Default)]
pub struct FundingControllerGetProjectedFundingRateParams {
pub product_id: String,
}
#[derive(Clone, Debug, Default)]
pub struct FundingControllerListByProductIdParams {
pub product_id: String,
pub range: String,
pub order: Option<String>,
pub limit: Option<f64>,
pub cursor: Option<String>,
pub order_by: Option<String>,
}
#[derive(Clone, Debug, Default)]
pub struct FundingControllerListProjectedRatesParams {
pub product_ids: Vec<uuid::Uuid>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FundingControllerGetProjectedFundingRateError {
Status400(models::BadRequestDto),
Status401(models::UnauthorizedDto),
Status403(models::ForbiddenDto),
Status404(models::NotFoundDto),
Status422(models::UnprocessableEntityDto),
Status429(models::TooManyRequestsDto),
Status500(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FundingControllerListByProductIdError {
Status400(models::BadRequestDto),
Status401(models::UnauthorizedDto),
Status403(models::ForbiddenDto),
Status404(models::NotFoundDto),
Status422(models::UnprocessableEntityDto),
Status429(models::TooManyRequestsDto),
Status500(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FundingControllerListProjectedRatesError {
Status400(models::BadRequestDto),
Status401(models::UnauthorizedDto),
Status403(models::ForbiddenDto),
Status404(models::NotFoundDto),
Status422(models::UnprocessableEntityDto),
Status429(models::TooManyRequestsDto),
Status500(),
UnknownValue(serde_json::Value),
}
pub async fn funding_controller_get_projected_funding_rate(
configuration: &configuration::Configuration,
params: FundingControllerGetProjectedFundingRateParams,
) -> Result<models::ProjectedFundingDto, Error<FundingControllerGetProjectedFundingRateError>> {
let uri_str = format!("{}/v1/funding/projected", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = req_builder.query(&[("productId", ¶ms.product_id.to_string())]);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
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::ProjectedFundingDto`"))),
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::ProjectedFundingDto`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<FundingControllerGetProjectedFundingRateError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn funding_controller_list_by_product_id(
configuration: &configuration::Configuration,
params: FundingControllerListByProductIdParams,
) -> Result<models::PageOfFundingDtos, Error<FundingControllerListByProductIdError>> {
let uri_str = format!("{}/v1/funding", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = params.order {
req_builder = req_builder.query(&[("order", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = params.cursor {
req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
}
req_builder = req_builder.query(&[("productId", ¶ms.product_id.to_string())]);
req_builder = req_builder.query(&[("range", ¶ms.range.to_string())]);
if let Some(ref param_value) = params.order_by {
req_builder = req_builder.query(&[("orderBy", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
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::PageOfFundingDtos`"))),
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::PageOfFundingDtos`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<FundingControllerListByProductIdError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn funding_controller_list_projected_rates(
configuration: &configuration::Configuration,
params: FundingControllerListProjectedRatesParams,
) -> Result<models::PageOfProjectedFundingDtos, Error<FundingControllerListProjectedRatesError>> {
let uri_str = format!("{}/v1/funding/projected-rate", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
req_builder = match "multi" {
"multi" => req_builder.query(
¶ms
.product_ids
.into_iter()
.map(|p| ("productIds".to_owned(), p.to_string()))
.collect::<Vec<(std::string::String, std::string::String)>>(),
),
_ => req_builder.query(&[(
"productIds",
¶ms
.product_ids
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]),
};
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
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::PageOfProjectedFundingDtos`"))),
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::PageOfProjectedFundingDtos`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<FundingControllerListProjectedRatesError> =
serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}