#![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,
user_information_api_client: UserInformationApiClient,
}
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());
let user_information_api_client = UserInformationApiClient::new(configuration.clone());
Self {
configuration,
market_data_api_client,
trade_api_client,
user_information_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 get_borrow_interest_rate(
&self,
params: GetBorrowInterestRateParams,
) -> anyhow::Result<RestApiResponse<Vec<models::GetBorrowInterestRateResponseInner>>> {
self.market_data_api_client
.get_borrow_interest_rate(params)
.await
}
pub async fn get_collateral_asset_data(
&self,
params: GetCollateralAssetDataParams,
) -> anyhow::Result<RestApiResponse<models::GetCollateralAssetDataResponse>> {
self.market_data_api_client
.get_collateral_asset_data(params)
.await
}
pub async fn get_loanable_assets_data(
&self,
params: GetLoanableAssetsDataParams,
) -> anyhow::Result<RestApiResponse<models::GetLoanableAssetsDataResponse>> {
self.market_data_api_client
.get_loanable_assets_data(params)
.await
}
pub async fn vip_loan_borrow(
&self,
params: VipLoanBorrowParams,
) -> anyhow::Result<RestApiResponse<models::VipLoanBorrowResponse>> {
self.trade_api_client.vip_loan_borrow(params).await
}
pub async fn vip_loan_renew(
&self,
params: VipLoanRenewParams,
) -> anyhow::Result<RestApiResponse<models::VipLoanRenewResponse>> {
self.trade_api_client.vip_loan_renew(params).await
}
pub async fn vip_loan_repay(
&self,
params: VipLoanRepayParams,
) -> anyhow::Result<RestApiResponse<models::VipLoanRepayResponse>> {
self.trade_api_client.vip_loan_repay(params).await
}
pub async fn check_vip_loan_collateral_account(
&self,
params: CheckVipLoanCollateralAccountParams,
) -> anyhow::Result<RestApiResponse<models::CheckVipLoanCollateralAccountResponse>> {
self.user_information_api_client
.check_vip_loan_collateral_account(params)
.await
}
pub async fn get_vip_loan_ongoing_orders(
&self,
params: GetVipLoanOngoingOrdersParams,
) -> anyhow::Result<RestApiResponse<models::GetVipLoanOngoingOrdersResponse>> {
self.user_information_api_client
.get_vip_loan_ongoing_orders(params)
.await
}
pub async fn query_application_status(
&self,
params: QueryApplicationStatusParams,
) -> anyhow::Result<RestApiResponse<models::QueryApplicationStatusResponse>> {
self.user_information_api_client
.query_application_status(params)
.await
}
}