polyte_data/api/
live_volume.rs1use polyte_core::RequestError;
2use reqwest::Client;
3use serde::{Deserialize, Serialize};
4use url::Url;
5
6use crate::error::{DataApiError, Result};
7
8#[derive(Clone)]
10pub struct LiveVolumeApi {
11 pub(crate) client: Client,
12 pub(crate) base_url: Url,
13}
14
15impl LiveVolumeApi {
16 pub async fn get(&self, event_id: u64) -> Result<Vec<LiveVolume>> {
18 let url = self.base_url.join("/live-volume")?;
19 let response = self
20 .client
21 .get(url)
22 .query(&[("id", event_id)])
23 .send()
24 .await?;
25 let status = response.status();
26
27 if !status.is_success() {
28 return Err(DataApiError::from_response(response).await);
29 }
30
31 let volume: Vec<LiveVolume> = response.json().await?;
32 Ok(volume)
33 }
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct LiveVolume {
39 pub total: f64,
41 pub markets: Vec<MarketVolume>,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct MarketVolume {
48 pub market: String,
50 pub value: f64,
52}