use super::models::{MarketBooks, MarketTicker, MarketTickers, RestApi};
use crate::client::OkxClient;
use anyhow::Result;
use std::collections::BTreeMap;
impl OkxClient {
pub async fn market_tickers<T>(
&self,
inst_type: T,
uly: Option<T>,
inst_family: Option<T>,
) -> Result<RestApi<MarketTickers>>
where
T: Into<String>,
{
let mut params: BTreeMap<String, String> = BTreeMap::new();
if let Some(uly) = uly {
params.insert("uly".into(), uly.into());
}
if let Some(inst_family) = inst_family {
params.insert("instFamily".into(), inst_family.into());
}
params.insert("instType".into(), inst_type.into());
Ok(self
.get::<RestApi<MarketTickers>>("/api/v5/market/tickers", ¶ms)
.await?)
}
pub async fn market_ticker<T>(&self, inst_id: T) -> Result<RestApi<MarketTicker>>
where
T: Into<String>,
{
let mut params: BTreeMap<String, String> = BTreeMap::new();
params.insert("instId".into(), inst_id.into());
Ok(self
.get::<RestApi<MarketTicker>>("/api/v5/market/ticker", ¶ms)
.await?)
}
pub async fn market_books<T>(&self, inst_id: T, sz: Option<T>) -> Result<RestApi<MarketBooks>>
where
T: Into<String>,
{
let mut params: BTreeMap<String, String> = BTreeMap::new();
params.insert("instId".into(), inst_id.into());
if let Some(sz) = sz {
params.insert("sz".into(), sz.into());
}
Ok(self
.get::<RestApi<MarketBooks>>("/api/v5/market/books", ¶ms)
.await?)
}
}