use crate::prelude::*;
#[derive(Clone)]
pub struct Markets {
pub client: Client,
}
impl Markets {
pub async fn browse_active(
&self,
category_id: Option<u64>,
page: Option<u64>,
limit: Option<u64>,
sort_by: Option<String>,
trade_type: Option<String>,
automation_type: Option<String>,
) -> Result<ActiveMarketsResponse, LimitlessError> {
let mut params = BTreeMap::new();
if let Some(v) = page {
params.insert("page".into(), v.to_string());
}
if let Some(v) = limit {
params.insert("limit".into(), v.to_string());
}
if let Some(ref v) = sort_by {
params.insert("sortBy".into(), v.clone());
}
if let Some(ref v) = trade_type {
params.insert("tradeType".into(), v.clone());
}
if let Some(ref v) = automation_type {
params.insert("automationType".into(), v.clone());
}
let request = build_request(¶ms);
let path = if let Some(cat_id) = category_id {
format!("markets/active/{}", cat_id)
} else {
"markets/active".to_string()
};
self.client.get(&path, Some(request)).await
}
pub async fn get_category_counts(&self) -> Result<CategoryCountResponse, LimitlessError> {
self.client.get("markets/categories/count", None).await
}
pub async fn get_active_slugs(&self) -> Result<Vec<ActiveSlug>, LimitlessError> {
self.client.get("markets/active/slugs", None).await
}
pub async fn get_market(&self, address_or_slug: &str) -> Result<MarketDetail, LimitlessError> {
let path = format!("markets/{}", address_or_slug);
self.client.get(&path, None).await
}
pub async fn get_oracle_candles(
&self,
address_or_slug: &str,
interval: Option<&str>,
from: Option<u64>,
to: Option<u64>,
) -> Result<OracleCandlesResponse, LimitlessError> {
let mut params = BTreeMap::new();
if let Some(ref v) = interval {
params.insert("interval".into(), v.to_string());
}
if let Some(v) = from {
params.insert("from".into(), v.to_string());
}
if let Some(v) = to {
params.insert("to".into(), v.to_string());
}
let request = build_request(¶ms);
let path = format!("markets/{}/oracle-candles", address_or_slug);
self.client.get(&path, Some(request)).await
}
pub async fn get_feed_events(
&self,
slug: &str,
page: Option<u64>,
limit: Option<u64>,
) -> Result<FeedEventsResponse, LimitlessError> {
let mut params = BTreeMap::new();
if let Some(v) = page {
params.insert("page".into(), v.to_string());
}
if let Some(v) = limit {
params.insert("limit".into(), v.to_string());
}
let request = build_request(¶ms);
let path = format!("markets/{}/get-feed-events", slug);
self.client.get(&path, Some(request)).await
}
pub async fn search(
&self,
query: &str,
limit: Option<u64>,
page: Option<u64>,
similarity_threshold: Option<f64>,
) -> Result<SearchResponse, LimitlessError> {
let mut params = BTreeMap::new();
params.insert("query".into(), query.to_string());
if let Some(v) = limit {
params.insert("limit".into(), v.to_string());
}
if let Some(v) = page {
params.insert("page".into(), v.to_string());
}
if let Some(v) = similarity_threshold {
params.insert("similarityThreshold".into(), v.to_string());
}
let request = build_request(¶ms);
self.client.get("markets/search", Some(request)).await
}
}
impl Limitless for Markets {
fn new(api_key: Option<String>, secret: Option<String>) -> Self {
Self::new_with_config(&Config::default(), api_key, secret)
}
fn new_with_config(config: &Config, api_key: Option<String>, secret: Option<String>) -> Self {
Self {
client: Client::new(api_key, secret, config.rest_api_endpoint.to_string()),
}
}
}