Skip to main content

finance_query/models/crypto/
mod.rs

1//! Cryptocurrency data models.
2//!
3//! Canonical public types for cryptocurrency quotes from multiple providers.
4
5use serde::{Deserialize, Serialize};
6
7/// A provider-agnostic cryptocurrency quote.
8///
9/// Obtain via [`Ticker::crypto_quote`](crate::Ticker::crypto_quote). Supported providers:
10/// Alpha Vantage, CoinGecko, FMP, Polygon.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12#[non_exhaustive]
13pub struct CryptoQuote {
14    /// Coin identifier (e.g., `"bitcoin"` for CoinGecko, `"BTC"` for others)
15    pub id: String,
16    /// Ticker symbol in uppercase (e.g., `"BTC"`, `"ETH"`)
17    pub symbol: String,
18    /// Full coin name (e.g., `"Bitcoin"`)
19    pub name: String,
20    /// Current price in the requested currency
21    pub price: Option<f64>,
22    /// Market capitalisation
23    pub market_cap: Option<f64>,
24    /// 24-hour trading volume
25    pub volume_24h: Option<f64>,
26    /// 24-hour absolute price change
27    pub change_24h: Option<f64>,
28    /// 24-hour price change percentage
29    pub change_percent_24h: Option<f64>,
30    /// 24-hour high
31    pub high_24h: Option<f64>,
32    /// 24-hour low
33    pub low_24h: Option<f64>,
34    /// Circulating supply
35    pub circulating_supply: Option<f64>,
36}
37
38/// A cryptocurrency quote from CoinGecko.
39///
40/// Obtain via [`crypto::coins`](crate::crypto::coins) or [`crypto::coin`](crate::crypto::coin).
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[non_exhaustive]
43pub struct CoinQuote {
44    /// CoinGecko coin ID (e.g., `"bitcoin"`, `"ethereum"`)
45    pub id: String,
46    /// Ticker symbol in uppercase (e.g., `"BTC"`, `"ETH"`)
47    pub symbol: String,
48    /// Full coin name (e.g., `"Bitcoin"`)
49    pub name: String,
50    /// Current price in the requested currency
51    pub current_price: Option<f64>,
52    /// Market capitalisation
53    pub market_cap: Option<f64>,
54    /// 24-hour price change percentage
55    pub price_change_percentage_24h: Option<f64>,
56    /// 24-hour trading volume
57    pub total_volume: Option<f64>,
58    /// Circulating supply
59    pub circulating_supply: Option<f64>,
60    /// URL to the coin's logo image
61    pub image: Option<String>,
62    /// Market cap rank (1 = highest market cap)
63    pub market_cap_rank: Option<u32>,
64}