use crate::config::Credentials;
use crate::{Error, OkxClient};
use reqwest::Method;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct VolumeData {
pub ts: String,
pub oi: String, pub vol: String, }
pub struct OkxContracts {
client: OkxClient,
}
impl OkxContracts {
pub fn new() -> Self {
Self {
client: OkxClient::new(Credentials::new("api_key", "api_secret", "passphrase", "0"))
.unwrap(),
}
}
pub fn from_env() -> Result<Self, Error> {
let client = OkxClient::from_env()?;
Ok(Self { client })
}
pub fn client(&self) -> &OkxClient {
&self.client
}
pub async fn get_open_interest_volume(
&self,
ccy: Option<&str>,
begin: Option<i64>,
end: Option<i64>,
period: Option<&str>,
) -> anyhow::Result<Vec<VolumeData>, anyhow::Error> {
let mut path = "/api/v5/rubik/stat/contracts/open-interest-volume?".to_string();
if let Some(ccy) = ccy {
path.push_str(&format!("&ccy={}", ccy));
}
if let Some(begin) = begin {
path.push_str(&format!("&begin={}", begin));
}
if let Some(end) = end {
path.push_str(&format!("&end={}", end));
}
if let Some(period) = period {
path.push_str(&format!("&period={}", period));
}
let res = self.client.send_request(Method::GET, &path, "").await?;
Ok(res)
}
}