finance-query v3.0.0

Crypto (CoinGecko)#

abstract · Cargo Docs

docs.rs/finance-query — crypto

info · Feature flag required

toml
finance-query = { version = "...", features = ["crypto"] }

The crypto module provides cryptocurrency market data via the CoinGecko public API. No API key is required. Rate limiting (30 req/min on the free tier) is handled automatically.

rust · feature=crypto
use finance_query::crypto;

Top Coins by Market Cap#

rust · no_run feature=crypto
use finance_query::crypto;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Top 10 coins in USD
    let top = crypto::coins("usd", 10).await?;

    for coin in &top {
        let price   = coin.current_price.unwrap_or(0.0);
        let change  = coin.price_change_percentage_24h.unwrap_or(0.0);
        let rank    = coin.market_cap_rank.unwrap_or(0);
        println!("#{} {} ({}): ${:.2} ({:+.2}%)", rank, coin.name, coin.symbol, price, change);
    }
    Ok(())
}
checked claims
de_crypto_coinsmedian time32.8 µs<200.0 µs
de_crypto_coinsCPU instructions352,875<700,000

The network round-trip, not parsing, dominates every call.

Single Coin Lookup#

rust · no_run feature=crypto
use finance_query::crypto;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Look up by CoinGecko ID
    let btc = crypto::coin("bitcoin", "usd").await?;
    println!("Bitcoin: ${:.2}", btc.current_price.unwrap_or(0.0));

    let eth = crypto::coin("ethereum", "usd").await?;
    let mktcap = eth.market_cap.unwrap_or(0.0);
    println!("Ethereum market cap: ${:.2}B", mktcap / 1e9);
    Ok(())
}
checked claims
CoinQuoteverified current

CoinGecko IDs are lowercase, hyphenated names. Common examples:

NameCoinGecko ID
Bitcoin"bitcoin"
Ethereum"ethereum"
BNB"binancecoin"
Solana"solana"
XRP"ripple"
USDC"usd-coin"
Dogecoin"dogecoin"

To discover IDs programmatically, call the CoinGecko /coins/list endpoint.

CoinQuote Fields#

FieldTypeDescription
idStringCoinGecko ID (e.g., "bitcoin")
symbolStringTicker symbol in uppercase (e.g., "BTC")
nameStringFull coin name (e.g., "Bitcoin")
current_priceOption<f64>Current price in the requested currency
market_capOption<f64>Market capitalisation
market_cap_rankOption<u32>Market cap rank (1 = largest)
price_change_percentage_24hOption<f64>24-hour price change (%)
total_volumeOption<f64>24-hour trading volume
circulating_supplyOption<f64>Circulating supply
imageOption<String>URL to the coin's logo image

Price History (keyless CHART route)#

Route Capability::CHART to CoinGecko and CryptoCoin serves OHLC history by coin id, without any API key:

rust,ignore
use finance_query::{Capability, Interval, Provider, Providers, TimeRange};

let providers = Providers::builder()
    .route(Capability::CHART, [Provider::CoinGecko])
    .build()
    .await?;

let chart = providers
    .crypto("bitcoin")
    .history("usd", TimeRange::ThreeMonths)
    .await?;
println!("{} candles", chart.candles.len());

Two properties of CoinGecko's public /ohlc endpoint carry through:

The handle's id and quote currency are recombined as "{id}-{vs}" and split on the last hyphen, so hyphenated CoinGecko ids (usd-coin, staked-ether) work.

Rate Limits#

The CoinGecko free tier allows 30 requests per minute. The client enforces this automatically — calls that would exceed the limit will wait until the window resets.

Next Steps#

built with cargo soothfast docs build source