#![allow(unused_imports)]
use http::Method;
use serde::de::DeserializeOwned;
use serde_json::Value;
use std::collections::BTreeMap;
use crate::common::{config::ConfigurationRestApi, models::RestApiResponse, utils::send_request};
mod apis;
mod models;
pub use apis::*;
pub use models::*;
#[derive(Debug, Clone)]
pub struct RestApi {
configuration: ConfigurationRestApi,
market_data_api_client: MarketDataApiClient,
}
impl RestApi {
pub fn new(configuration: ConfigurationRestApi) -> Self {
let market_data_api_client = MarketDataApiClient::new(configuration.clone());
Self {
configuration,
market_data_api_client,
}
}
pub async fn send_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
query_params: BTreeMap<String, Value>,
body_params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(
&self.configuration,
endpoint,
method,
query_params,
body_params,
None,
false,
)
.await
}
pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
query_params: BTreeMap<String, Value>,
body_params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(
&self.configuration,
endpoint,
method,
query_params,
body_params,
None,
true,
)
.await
}
pub async fn aggregated_trades(
&self,
params: AggregatedTradesParams,
) -> anyhow::Result<RestApiResponse<models::AggregatedTradesResponse>> {
self.market_data_api_client.aggregated_trades(params).await
}
pub async fn get_exchange_info(
&self,
) -> anyhow::Result<RestApiResponse<models::GetExchangeInfoResponse>> {
self.market_data_api_client.get_exchange_info().await
}
pub async fn klines(
&self,
params: KlinesParams,
) -> anyhow::Result<RestApiResponse<models::KlinesResponse>> {
self.market_data_api_client.klines(params).await
}
pub async fn ticker(
&self,
params: TickerParams,
) -> anyhow::Result<RestApiResponse<models::TickerResponse>> {
self.market_data_api_client.ticker(params).await
}
pub async fn token_list(&self) -> anyhow::Result<RestApiResponse<models::TokenListResponse>> {
self.market_data_api_client.token_list().await
}
}