#![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,
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 get_dual_investment_product_list(
&self,
params: GetDualInvestmentProductListParams,
) -> anyhow::Result<RestApiResponse<models::GetDualInvestmentProductListResponse>> {
self.market_data_api_client
.get_dual_investment_product_list(params)
.await
}
pub async fn change_auto_compound_status(
&self,
params: ChangeAutoCompoundStatusParams,
) -> anyhow::Result<RestApiResponse<models::ChangeAutoCompoundStatusResponse>> {
self.trade_api_client
.change_auto_compound_status(params)
.await
}
pub async fn check_dual_investment_accounts(
&self,
params: CheckDualInvestmentAccountsParams,
) -> anyhow::Result<RestApiResponse<models::CheckDualInvestmentAccountsResponse>> {
self.trade_api_client
.check_dual_investment_accounts(params)
.await
}
pub async fn get_dual_investment_positions(
&self,
params: GetDualInvestmentPositionsParams,
) -> anyhow::Result<RestApiResponse<models::GetDualInvestmentPositionsResponse>> {
self.trade_api_client
.get_dual_investment_positions(params)
.await
}
pub async fn subscribe_dual_investment_products(
&self,
params: SubscribeDualInvestmentProductsParams,
) -> anyhow::Result<RestApiResponse<models::SubscribeDualInvestmentProductsResponse>> {
self.trade_api_client
.subscribe_dual_investment_products(params)
.await
}
}