coinpaprika_api/global/
mod.rs

1use crate::client::{Client, Response};
2use crate::error::Error;
3use reqwest_middleware::RequestBuilder;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize, Deserialize)]
7/// Global market overview data
8pub struct Global {
9    /// Total market capitalization - sum of all cryptocurrency market capitalizations in USD
10    pub market_cap_usd: i64,
11
12    /// Total 24h volume - sum of all cryptocurrency volumes in USD
13    pub volume_24h_usd: i64,
14
15    /// Bitcoin market capitalization as a percentage of total market capitalization
16    pub bitcoin_dominance_percentage: f64,
17
18    /// This is number of active cryptocurrencies on our site (active in this case means that we
19    /// have up-to-date price data for a coin). Total number of our cryptocurrencies is higher and
20    /// may be obtained via counting elements in /coins endpoint.
21    pub cryptocurrencies_number: i32,
22
23    /// ATH (All Time High) value of market capitalization - the highest historical value of
24    /// marketcap
25    pub market_cap_ath_value: i64,
26
27    /// ATH (All Time High) date of market capitalization
28    pub market_cap_ath_date: String,
29
30    /// ATH (All Time High) value of the 24h volume - the highest historical value of 24h volume
31    pub volume_24h_ath_value: i64,
32
33    /// ATH (All Time High) date of volume 24h
34    pub volume_24h_ath_date: String,
35
36    /// Percentage change in the market capitalization over the last 24h
37    pub market_cap_change_24h: f64,
38
39    /// Percentage change in the volume 24h over the last 24h
40    pub volume_24h_change_24h: f64,
41
42    /// Timestamp of the last data update
43    pub last_updated: i64,
44}
45
46/// Request for getting global market overview data
47/// [/global](https://api.coinpaprika.com/#tag/Global/paths/~1global/get)
48pub struct GetGlobalRequest<'a> {
49    client: &'a Client,
50}
51
52impl<'a> GetGlobalRequest<'a> {
53    pub fn new(client: &'a Client) -> Self {
54        Self { client }
55    }
56
57    pub async fn send(&self) -> Result<Global, Error> {
58        let request: RequestBuilder = self
59            .client
60            .client
61            .get(format!("{}/global", self.client.api_url));
62
63        let response: Response = self.client.request(request).await?;
64
65        let data: Global = response.response.json().await?;
66
67        Ok(data)
68    }
69}