polyte_data/api/
live_volume.rs

1use reqwest::Client;
2use serde::{Deserialize, Serialize};
3use url::Url;
4
5use crate::error::{DataApiError, Result};
6
7/// LiveVolume namespace for live volume operations
8#[derive(Clone)]
9pub struct LiveVolumeApi {
10    pub(crate) client: Client,
11    pub(crate) base_url: Url,
12}
13
14impl LiveVolumeApi {
15    /// Get live volume for an event
16    pub async fn get(&self, event_id: u64) -> Result<Vec<LiveVolume>> {
17        let url = self.base_url.join("/live-volume")?;
18        let response = self
19            .client
20            .get(url)
21            .query(&[("id", event_id)])
22            .send()
23            .await?;
24        let status = response.status();
25
26        if !status.is_success() {
27            return Err(DataApiError::from_response(response).await);
28        }
29
30        let volume: Vec<LiveVolume> = response.json().await?;
31        Ok(volume)
32    }
33}
34
35/// Live volume for an event
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct LiveVolume {
38    /// Total aggregated volume
39    pub total: f64,
40    /// Per-market volume breakdown
41    pub markets: Vec<MarketVolume>,
42}
43
44/// Volume for a specific market
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct MarketVolume {
47    /// Market condition ID
48    pub market: String,
49    /// Volume value
50    pub value: f64,
51}