use crate::{kalshi_error::*, Kalshi};
use serde::Deserialize;
use serde_json::Value;
impl Kalshi {
pub async fn get_multivariate_event_collections(
&self,
limit: Option<i64>,
cursor: Option<String>,
) -> Result<(Option<String>, Vec<Collection>), KalshiError> {
let mut p = Vec::new();
add_param!(p, "limit", limit);
add_param!(p, "cursor", cursor);
let path = if p.is_empty() {
"/multivariate_event_collections".to_string()
} else {
format!(
"/multivariate_event_collections?{}",
serde_urlencoded::to_string(&p)?
)
};
let res: CollectionListResponse = self.signed_get(&path).await?;
Ok((res.cursor, res.multivariate_event_collections))
}
pub async fn get_multivariate_event_collection(
&self,
collection_ticker: &str,
) -> Result<Collection, KalshiError> {
let path = format!("/multivariate_event_collections/{collection_ticker}");
let res: SingleCollectionResponse = self.signed_get(&path).await?;
Ok(res.multivariate_event_collection)
}
pub async fn get_collection_lookup_history(
&self,
collection_ticker: &str,
limit: Option<i64>,
cursor: Option<String>,
) -> Result<(Option<String>, Vec<LookupEntry>), KalshiError> {
let mut p = Vec::new();
add_param!(p, "limit", limit);
add_param!(p, "cursor", cursor);
let query = if p.is_empty() {
String::new()
} else {
format!("?{}", serde_urlencoded::to_string(&p)?)
};
let path = format!("/multivariate_event_collections/{collection_ticker}/lookup{query}");
let res: LookupHistoryResponse = self.signed_get(&path).await?;
Ok((res.cursor, res.lookups))
}
pub async fn create_market_in_collection(
&self,
collection_ticker: &str,
body: &Value,
) -> Result<Collection, KalshiError> {
let path = format!("/multivariate_event_collections/{collection_ticker}");
let res: SingleCollectionResponse = self.signed_post(&path, body).await?;
Ok(res.multivariate_event_collection)
}
pub async fn lookup_tickers_for_market(
&self,
collection_ticker: &str,
body: &Value,
) -> Result<Collection, KalshiError> {
let path = format!("/multivariate_event_collections/{collection_ticker}/tickers");
let res: SingleCollectionResponse = self.signed_put(&path, Some(body)).await?;
Ok(res.multivariate_event_collection)
}
}
pub type Collection = Value;
pub type LookupEntry = Value;
#[derive(Debug, Deserialize)]
struct CollectionListResponse {
cursor: Option<String>,
multivariate_event_collections: Vec<Collection>,
}
#[derive(Debug, Deserialize)]
struct SingleCollectionResponse {
multivariate_event_collection: Collection,
}
#[derive(Debug, Deserialize)]
struct LookupHistoryResponse {
cursor: Option<String>,
lookups: Vec<LookupEntry>,
}