Skip to main content

polyoxide_data/api/
open_interest.rs

1use polyoxide_core::{HttpClient, QueryBuilder, Request};
2
3use crate::{error::DataApiError, types::OpenInterest};
4
5/// OpenInterest namespace for open interest operations
6#[derive(Clone)]
7pub struct OpenInterestApi {
8    pub(crate) http_client: HttpClient,
9}
10
11impl OpenInterestApi {
12    /// Get open interest for markets
13    pub fn get(&self) -> GetOpenInterest {
14        GetOpenInterest {
15            request: Request::new(self.http_client.clone(), "/oi"),
16        }
17    }
18}
19
20/// Request builder for getting open interest
21pub struct GetOpenInterest {
22    request: Request<Vec<OpenInterest>, DataApiError>,
23}
24
25impl GetOpenInterest {
26    /// Filter by specific market condition IDs
27    pub fn market(mut self, condition_ids: impl IntoIterator<Item = impl ToString>) -> Self {
28        let ids: Vec<String> = condition_ids.into_iter().map(|s| s.to_string()).collect();
29        if !ids.is_empty() {
30            self.request = self.request.query("market", ids.join(","));
31        }
32        self
33    }
34
35    /// Execute the request
36    pub async fn send(self) -> Result<Vec<OpenInterest>, DataApiError> {
37        self.request.send().await
38    }
39}