finance_query/models/crypto/mod.rs
1//! Cryptocurrency data models.
2//!
3//! Canonical public types for cryptocurrency quotes from multiple providers.
4
5/// DeFi protocol and chain models — DefiLlama.
6#[cfg(feature = "defi")]
7pub mod defi;
8
9use serde::{Deserialize, Serialize};
10
11/// A provider-agnostic cryptocurrency quote.
12///
13/// Obtain via [`Providers::crypto`](crate::Providers::crypto) then
14/// [`.quote()`](crate::domains::CryptoCoin::quote). Supported providers:
15/// Alpha Vantage, CoinGecko, FMP, Polygon.
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[non_exhaustive]
18pub struct CryptoQuote {
19 /// Coin identifier (e.g., `"bitcoin"` for CoinGecko, `"BTC"` for others)
20 pub id: String,
21 /// Ticker symbol in uppercase (e.g., `"BTC"`, `"ETH"`)
22 pub symbol: String,
23 /// Full coin name (e.g., `"Bitcoin"`)
24 pub name: String,
25 /// Current price in the requested currency
26 pub price: Option<f64>,
27 /// Market capitalisation
28 pub market_cap: Option<f64>,
29 /// 24-hour trading volume
30 pub volume_24h: Option<f64>,
31 /// 24-hour absolute price change
32 pub change_24h: Option<f64>,
33 /// 24-hour price change percentage
34 pub change_percent_24h: Option<f64>,
35 /// 24-hour high
36 pub high_24h: Option<f64>,
37 /// 24-hour low
38 pub low_24h: Option<f64>,
39 /// Circulating supply
40 pub circulating_supply: Option<f64>,
41}
42
43/// A cryptocurrency quote from CoinGecko.
44///
45/// Obtain via [`crypto::coins`](crate::crypto::coins) or [`crypto::coin`](crate::crypto::coin).
46#[cfg(feature = "crypto")]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[non_exhaustive]
49pub struct CoinQuote {
50 /// CoinGecko coin ID (e.g., `"bitcoin"`, `"ethereum"`)
51 pub id: String,
52 /// Ticker symbol in uppercase (e.g., `"BTC"`, `"ETH"`)
53 pub symbol: String,
54 /// Full coin name (e.g., `"Bitcoin"`)
55 pub name: String,
56 /// Current price in the requested currency
57 pub current_price: Option<f64>,
58 /// Market capitalisation
59 pub market_cap: Option<f64>,
60 /// 24-hour price change percentage
61 pub price_change_percentage_24h: Option<f64>,
62 /// 24-hour trading volume
63 pub total_volume: Option<f64>,
64 /// Circulating supply
65 pub circulating_supply: Option<f64>,
66 /// URL to the coin's logo image
67 pub image: Option<String>,
68 /// Market cap rank (1 = highest market cap)
69 pub market_cap_rank: Option<u32>,
70}
71
72/// A coin trending in the last 24h, from CoinGecko's `/search/trending`.
73///
74/// Obtain via [`Market::crypto_trending`](crate::domains::Market::crypto_trending).
75#[cfg(feature = "crypto")]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[non_exhaustive]
78pub struct TrendingCoin {
79 /// CoinGecko coin ID (e.g., `"bitcoin"`)
80 pub id: Option<String>,
81 /// Ticker symbol in uppercase (e.g., `"BTC"`)
82 pub symbol: Option<String>,
83 /// Full coin name (e.g., `"Bitcoin"`)
84 pub name: Option<String>,
85 /// Market cap rank (1 = highest market cap)
86 pub market_cap_rank: Option<u32>,
87 /// Price denominated in BTC
88 pub price_btc: Option<f64>,
89 /// Trending rank (0 = most trending)
90 pub score: Option<u32>,
91}
92
93/// Aggregate global cryptocurrency market statistics, from CoinGecko's `/global`.
94///
95/// Obtain via [`Market::crypto_global`](crate::domains::Market::crypto_global).
96#[cfg(feature = "crypto")]
97#[derive(Debug, Clone, Serialize, Deserialize)]
98#[non_exhaustive]
99pub struct GlobalCryptoStats {
100 /// Number of active cryptocurrencies tracked
101 pub active_cryptocurrencies: Option<u32>,
102 /// Number of markets tracked
103 pub markets: Option<u32>,
104 /// Total market capitalisation in USD across all tracked coins
105 pub total_market_cap_usd: Option<f64>,
106 /// Total 24-hour trading volume in USD across all tracked coins
107 pub total_volume_usd: Option<f64>,
108 /// Bitcoin's percentage of total market cap
109 pub btc_dominance: Option<f64>,
110 /// Ethereum's percentage of total market cap
111 pub eth_dominance: Option<f64>,
112 /// 24-hour percentage change in total market cap (USD)
113 pub market_cap_change_percentage_24h_usd: Option<f64>,
114}