ethereal_rust_sdk 0.1.22

Trading client for Ethereal exchange
Documentation
/*
 * Ethereal Exchange API
 *
 * Ethereal HTTP API for real-time trading, order management, and market data access.
 *
 * The version of the OpenAPI document: 0.1.0
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};

/// struct for passing parameters to the method [`points_controller_get_total_points`]
#[derive(Clone, Debug, Default)]
pub struct PointsControllerGetTotalPointsParams {
    /// Season number
    pub season: Option<f64>,
    /// Epoch number within season
    pub epoch: Option<f64>,
}

/// struct for passing parameters to the method [`points_controller_list_points_periods`]
#[derive(Clone, Debug, Default)]
pub struct PointsControllerListPointsPeriodsParams {
    /// Address of account
    pub address: String,
    /// Season number
    pub season: f64,
    /// Epoch number within the season
    pub epoch: f64,
}

/// struct for passing parameters to the method [`points_controller_list_points_season_summaries`]
#[derive(Clone, Debug, Default)]
pub struct PointsControllerListPointsSeasonSummariesParams {
    /// Address of account
    pub address: String,
}

/// struct for typed errors of method [`points_controller_get_total_points`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointsControllerGetTotalPointsError {
    Status400(models::BadRequestDto),
    Status401(models::UnauthorizedDto),
    Status403(models::ForbiddenDto),
    Status404(models::NotFoundDto),
    Status422(models::UnprocessableEntityDto),
    Status429(models::TooManyRequestsDto),
    Status500(),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`points_controller_list_points_periods`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointsControllerListPointsPeriodsError {
    Status400(models::BadRequestDto),
    Status401(models::UnauthorizedDto),
    Status403(models::ForbiddenDto),
    Status404(models::NotFoundDto),
    Status422(models::UnprocessableEntityDto),
    Status429(models::TooManyRequestsDto),
    Status500(),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`points_controller_list_points_season_summaries`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PointsControllerListPointsSeasonSummariesError {
    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 points_controller_get_total_points(
    configuration: &configuration::Configuration,
    params: PointsControllerGetTotalPointsParams,
) -> Result<models::TotalPointsDto, Error<PointsControllerGetTotalPointsError>> {
    let uri_str = format!("{}/v1/points/total", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref param_value) = params.season {
        req_builder = req_builder.query(&[("season", &param_value.to_string())]);
    }
    if let Some(ref param_value) = params.epoch {
        req_builder = req_builder.query(&[("epoch", &param_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::TotalPointsDto`"))),
            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::TotalPointsDto`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PointsControllerGetTotalPointsError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

pub async fn points_controller_list_points_periods(
    configuration: &configuration::Configuration,
    params: PointsControllerListPointsPeriodsParams,
) -> Result<models::ListOfPointsPeriodDtos, Error<PointsControllerListPointsPeriodsError>> {
    let uri_str = format!("{}/v1/points", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("address", &params.address.to_string())]);
    req_builder = req_builder.query(&[("season", &params.season.to_string())]);
    req_builder = req_builder.query(&[("epoch", &params.epoch.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::ListOfPointsPeriodDtos`"))),
            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::ListOfPointsPeriodDtos`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PointsControllerListPointsPeriodsError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

pub async fn points_controller_list_points_season_summaries(
    configuration: &configuration::Configuration,
    params: PointsControllerListPointsSeasonSummariesParams,
) -> Result<
    models::ListOfPointsSeasonSummariesDtos,
    Error<PointsControllerListPointsSeasonSummariesError>,
> {
    let uri_str = format!("{}/v1/points/summary", configuration.base_path);
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    req_builder = req_builder.query(&[("address", &params.address.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::ListOfPointsSeasonSummariesDtos`"))),
            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::ListOfPointsSeasonSummariesDtos`")))),
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<PointsControllerListPointsSeasonSummariesError> =
            serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}