#![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,
trade_api_client: TradeApiClient,
}
impl RestApi {
pub fn new(configuration: ConfigurationRestApi) -> Self {
let market_data_api_client = MarketDataApiClient::new(configuration.clone());
let trade_api_client = TradeApiClient::new(configuration.clone());
Self {
configuration,
market_data_api_client,
trade_api_client,
}
}
pub async fn send_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(&self.configuration, endpoint, method, params, None, false).await
}
pub async fn send_signed_request<R: DeserializeOwned + Send + 'static>(
&self,
endpoint: &str,
method: Method,
params: BTreeMap<String, Value>,
) -> anyhow::Result<RestApiResponse<R>> {
send_request::<R>(&self.configuration, endpoint, method, params, None, true).await
}
pub async fn list_all_convert_pairs(
&self,
params: ListAllConvertPairsParams,
) -> anyhow::Result<RestApiResponse<Vec<models::ListAllConvertPairsResponseInner>>> {
self.market_data_api_client
.list_all_convert_pairs(params)
.await
}
pub async fn query_order_quantity_precision_per_asset(
&self,
params: QueryOrderQuantityPrecisionPerAssetParams,
) -> anyhow::Result<
RestApiResponse<Vec<models::QueryOrderQuantityPrecisionPerAssetResponseInner>>,
> {
self.market_data_api_client
.query_order_quantity_precision_per_asset(params)
.await
}
pub async fn accept_quote(
&self,
params: AcceptQuoteParams,
) -> anyhow::Result<RestApiResponse<models::AcceptQuoteResponse>> {
self.trade_api_client.accept_quote(params).await
}
pub async fn cancel_limit_order(
&self,
params: CancelLimitOrderParams,
) -> anyhow::Result<RestApiResponse<models::CancelLimitOrderResponse>> {
self.trade_api_client.cancel_limit_order(params).await
}
pub async fn get_convert_trade_history(
&self,
params: GetConvertTradeHistoryParams,
) -> anyhow::Result<RestApiResponse<models::GetConvertTradeHistoryResponse>> {
self.trade_api_client
.get_convert_trade_history(params)
.await
}
pub async fn order_status(
&self,
params: OrderStatusParams,
) -> anyhow::Result<RestApiResponse<models::OrderStatusResponse>> {
self.trade_api_client.order_status(params).await
}
pub async fn place_limit_order(
&self,
params: PlaceLimitOrderParams,
) -> anyhow::Result<RestApiResponse<models::PlaceLimitOrderResponse>> {
self.trade_api_client.place_limit_order(params).await
}
pub async fn query_limit_open_orders(
&self,
params: QueryLimitOpenOrdersParams,
) -> anyhow::Result<RestApiResponse<models::QueryLimitOpenOrdersResponse>> {
self.trade_api_client.query_limit_open_orders(params).await
}
pub async fn send_quote_request(
&self,
params: SendQuoteRequestParams,
) -> anyhow::Result<RestApiResponse<models::SendQuoteRequestResponse>> {
self.trade_api_client.send_quote_request(params).await
}
}