mod client;
mod models;
use client::CoinGeckoClient;
use std::sync::OnceLock;
use crate::error::Result;
pub use crate::models::crypto::CoinQuote;
static COINGECKO_CLIENT: OnceLock<CoinGeckoClient> = OnceLock::new();
fn client() -> Result<&'static CoinGeckoClient> {
if COINGECKO_CLIENT.get().is_none() {
let _ = COINGECKO_CLIENT.set(CoinGeckoClient::new()?);
}
Ok(COINGECKO_CLIENT.get().expect("just set above"))
}
pub async fn coins(vs_currency: &str, count: usize) -> Result<Vec<CoinQuote>> {
client()?.coins(vs_currency, count).await
}
pub async fn coin(id: &str, vs_currency: &str) -> Result<CoinQuote> {
client()?.coin(id, vs_currency).await
}
pub async fn fetch_crypto_quote_response(
id: &str,
vs_currency: &str,
) -> Result<crate::models::crypto::CryptoQuote> {
let quote = coin(id, vs_currency).await?;
Ok(crate::models::crypto::CryptoQuote {
id: quote.id,
symbol: quote.symbol,
name: quote.name,
price: quote.current_price,
market_cap: quote.market_cap,
volume_24h: quote.total_volume,
change_24h: None,
change_percent_24h: quote.price_change_percentage_24h,
high_24h: None,
low_24h: None,
circulating_supply: quote.circulating_supply,
})
}