use reqwest::Method;
use crate::api::api_trait::OkxApiTrait;
use crate::client::{OkxApiResponse, OkxClient};
use crate::dto::big_data::*;
use crate::Error;
pub struct OkxBigData {
client: OkxClient,
}
impl OkxApiTrait for OkxBigData {
fn new(client: OkxClient) -> Self {
OkxBigData { client }
}
fn from_env() -> Result<Self, Error> {
let client = OkxClient::from_env()?;
Ok(OkxBigData::new(client))
}
fn client(&self) -> &OkxClient {
&self.client
}
}
impl OkxBigData {
pub async fn get_support_coin(&self) -> Result<OkxApiResponse<SupportCoin>, Error> {
let path = "/api/v5/rubik/stat/trading-data/support-coin?".to_string();
self.client.send_request(Method::GET, &path, "").await
}
pub async fn get_taker_volume(
&self,
ccy: &str,
inst_type: &str,
begin: Option<&str>,
end: Option<&str>,
period: Option<&str>,
) -> Result<Vec<Vec<String>>, Error> {
let mut path = format!(
"/api/v5/rubik/stat/taker-volume?ccy={}&instType={}",
ccy, inst_type
);
if let Some(begin_time) = begin {
path.push_str(&format!("&begin={}", begin_time));
}
if let Some(end_time) = end {
path.push_str(&format!("&end={}", end_time));
}
if let Some(period_value) = period {
path.push_str(&format!("&period={}", period_value));
}
self.client.send_request(Method::GET, &path, "").await
}
pub async fn get_taker_volume_contract(
&self,
inst_id: &str,
period: Option<&str>,
unit: Option<&str>,
begin: Option<&str>,
end: Option<&str>,
limit: Option<&str>,
) -> Result<Vec<Vec<String>>, Error> {
let mut path = format!(
"/api/v5/rubik/stat/taker-volume-contract?instId={}",
inst_id
);
if let Some(period_value) = period {
path.push_str(&format!("&period={}", period_value));
}
if let Some(unit_value) = unit {
path.push_str(&format!("&unit={}", unit_value));
}
if let Some(begin_time) = begin {
path.push_str(&format!("&begin={}", begin_time));
}
if let Some(end_time) = end {
path.push_str(&format!("&end={}", end_time));
}
if let Some(limit_value) = limit {
path.push_str(&format!("&limit={}", limit_value));
}
self.client.send_request(Method::GET, &path, "").await
}
pub async fn get_long_short_account_ratio_contract_top_trader(
&self,
inst_id: &str,
period: Option<&str>,
begin: Option<&str>,
end: Option<&str>,
limit: Option<&str>,
) -> Result<Vec<Vec<String>>, Error> {
let mut path = format!(
"/api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader?instId={}",
inst_id
);
if let Some(period_value) = period {
path.push_str(&format!("&period={}", period_value));
}
if let Some(begin_time) = begin {
path.push_str(&format!("&begin={}", begin_time));
}
if let Some(end_time) = end {
path.push_str(&format!("&end={}", end_time));
}
if let Some(limit_value) = limit {
path.push_str(&format!("&limit={}", limit_value));
}
self.client.send_request(Method::GET, &path, "").await
}
pub async fn get_long_short_postion_ratio_contract_top_trader(
&self,
inst_id: &str,
period: Option<&str>,
begin: Option<&str>,
end: Option<&str>,
limit: Option<&str>,
) -> Result<Vec<Vec<String>>, Error> {
let mut path = format!(
"/api/v5/rubik/stat/contracts/long-short-account-ratio-contract-top-trader?instId={}",
inst_id
);
if let Some(period_value) = period {
path.push_str(&format!("&period={}", period_value));
}
if let Some(begin_time) = begin {
path.push_str(&format!("&begin={}", begin_time));
}
if let Some(end_time) = end {
path.push_str(&format!("&end={}", end_time));
}
if let Some(limit_value) = limit {
path.push_str(&format!("&limit={}", limit_value));
}
self.client.send_request(Method::GET, &path, "").await
}
}