#![allow(unused)]
use async_trait::async_trait;
use std::{
collections::{BTreeMap, HashMap},
pin::Pin,
sync::Arc,
};
use futures::Future;
use reqwest::Method;
use serde_json::Value;
use crate::endpoints::v5spot_margin_trade;
use super::http_manager::{HttpManager, Manager};
#[async_trait]
pub trait SpotMarginTrade {
fn new(http_manager: Arc<HttpManager>) -> Self;
async fn spot_margin_trade_toggle_margin_trade(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_set_leverage(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_get_margin_coin_info(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_get_borrowable_coin_info(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_get_interest_quota(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_get_loan_account_info(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_borrow(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_repay(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_get_borrow_order_detail(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_get_repayment_order_detail(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
async fn spot_margin_trade_normal_toggle_margin_trade(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>>;
}
pub struct SpotMarginTradeHTTP {
http_manager: Arc<HttpManager>,
}
#[async_trait]
impl SpotMarginTrade for SpotMarginTradeHTTP {
fn new(http_manager: Arc<HttpManager>) -> Self {
SpotMarginTradeHTTP { http_manager }
}
async fn spot_margin_trade_toggle_margin_trade(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let endpoint = v5spot_margin_trade::SpotMarginTrade::ToggleMarginTrade.to_string();
self.http_manager
.submit_post_request(Method::POST, &endpoint, true, query)
.await
}
async fn spot_margin_trade_set_leverage(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let endpoint = v5spot_margin_trade::SpotMarginTrade::SetLeverage.to_string();
self.http_manager
.submit_post_request(Method::POST, &endpoint, true, query)
.await
}
async fn spot_margin_trade_normal_get_margin_coin_info(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let endpoint = v5spot_margin_trade::SpotMarginTrade::NormalGetMarginCoinInfo.to_string();
self.http_manager
.submit_request(Method::GET, &endpoint, query, false)
.await
}
async fn spot_margin_trade_normal_get_borrowable_coin_info(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let endpoint =
v5spot_margin_trade::SpotMarginTrade::NormalGetBorrowableCoinInfo.to_string();
self.http_manager
.submit_request(Method::GET, &endpoint, query, false)
.await
}
async fn spot_margin_trade_normal_get_interest_quota(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let endpoint = v5spot_margin_trade::SpotMarginTrade::NormalGetInterestQuota.to_string();
self.http_manager
.submit_request(Method::GET, &endpoint, query, false)
.await
}
async fn spot_margin_trade_normal_get_loan_account_info(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let endpoint = v5spot_margin_trade::SpotMarginTrade::NormalGetLoanAccountInfo.to_string();
self.http_manager
.submit_request(Method::GET, &endpoint, query, false)
.await
}
async fn spot_margin_trade_normal_borrow(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut endpoint = v5spot_margin_trade::SpotMarginTrade::NormalBorrow.to_string();
endpoint = endpoint.replace("$instrument_id", &query["instrument_id"]);
self.http_manager
.submit_post_request(Method::POST, &endpoint, true, query)
.await
}
async fn spot_margin_trade_normal_repay(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut endpoint = v5spot_margin_trade::SpotMarginTrade::NormalRepay.to_string();
endpoint = endpoint.replace("$instrument_id", &query["instrument_id"]);
self.http_manager
.submit_post_request(Method::POST, &endpoint, true, query)
.await
}
async fn spot_margin_trade_normal_get_borrow_order_detail(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut endpoint =
v5spot_margin_trade::SpotMarginTrade::NormalGetBorrowOrderDetail.to_string();
endpoint = endpoint.replace("$instrument_id", &query["instrument_id"]);
endpoint = endpoint.replace("$borrow_id", &query["borrow_id"]);
self.http_manager
.submit_request(Method::GET, &endpoint, query, false)
.await
}
async fn spot_margin_trade_normal_get_repayment_order_detail(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut endpoint =
v5spot_margin_trade::SpotMarginTrade::NormalGetRepaymentOrderDetail.to_string();
endpoint = endpoint.replace("$instrument_id", &query["instrument_id"]);
endpoint = endpoint.replace("$repayment_id", &query["repayment_id"]);
self.http_manager
.submit_request(Method::GET, &endpoint, query, false)
.await
}
async fn spot_margin_trade_normal_toggle_margin_trade(
&self,
query: HashMap<String, String>,
) -> Result<Value, Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut endpoint =
v5spot_margin_trade::SpotMarginTrade::NormalToggleMarginTrade.to_string();
endpoint = endpoint.replace("$instrument_id", &query["instrument_id"]);
self.http_manager
.submit_post_request(Method::POST, &endpoint, true, query)
.await
}
}