finance-query v3.0.0

Binance (public market data)#

info · Feature flag required

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

Binance's public market-data endpoints need no API key. The adapter talks to data-api.binance.vision — the market-data-only host, which serves the same public endpoints as api.binance.com but carries no account or trading routes, so there is no key to configure and none to leak.

This is the first keyless source of exchange-grade crypto data in the library: CoinGecko is aggregated and coarse, and the keyed providers charge for OHLCV.

warning · Geo-blocked in some regions

Binance restricts some regions (notably US retail) and answers with HTTP 451. That surfaces as a FinanceError::ApiError naming Kraken as the alternative. Chain the two if you need coverage everywhere.

Capabilities#

CapabilityWhat Binance serves
CRYPTORolling 24-hour quote per spot market
CHARTArbitrary-interval OHLCV klines
rust · no_run feature=binance
use finance_query::{Capability, Interval, Provider, Providers, TimeRange};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let providers = Providers::builder()
        .route(Capability::CRYPTO, [Provider::Binance])
        .route(Capability::CHART, [Provider::Binance])
        .build()
        .await?;

    let btc = providers.crypto("bitcoin");
    let quote = btc.quote("usd").await?;
    println!("BTC {:?} ({:+.2?}%)", quote.price, quote.change_percent_24h);

    let chart = btc.chart("usd", Interval::OneHour, TimeRange::OneMonth).await?;
    println!("{} hourly candles", chart.candles.len());
    Ok(())
}

note · Routing `CHART` is global

Capability::CHART is one route for the whole library. Pointing it at Binance means equity charts go there too — Binance answers a symbol it cannot map to a spot market with NotSupported, so under Fetch::Sequential list Yahoo after it: .route(Capability::CHART, [Provider::Binance, Provider::Yahoo])

Symbols#

Binance names a market as one concatenated string with no separator (BTCUSDT). Every spelling the library uses is accepted:

You passBinance market
crypto("bitcoin").quote("usd")BTCUSDT
crypto("BTC").quote("eur")BTCEUR
chart symbol BTC-USDBTCUSDT
chart symbol BTCUSDTBTCUSDT
chart symbol ETH/BTCETHBTC

CoinGecko-style coin ids are recognised for about 25 majors so a route swap between CoinGecko and Binance does not change your call sites. Anything not in that list is treated as a ticker, which is usually right.

warning · USD means USDT

Binance spot lists no USD markets — dollar pairs are quoted in the USDT stablecoin. "usd" is therefore mapped to USDT. That is what callers mean in practice, but USDT is not literally the US dollar and can trade off its peg.

Response Notes#

CryptoQuote:

Chart:

Intervals#

Every library interval maps to a Binance kline code except ThreeMonths, which Binance does not offer — that returns NotSupported, so sequential routing falls through to the next provider.

Binance caps a single kline response at 1000 candles. Longer windows are walked forward automatically, up to 10 requests (10,000 candles) per chart — enough for five years of daily or a year of hourly data.

Rate Limits#

Binance meters by request weight (6000 per minute per IP); the endpoints used here are weight 1–2. The client paces at 10 requests/second, well inside that. A 429 — or a 418, Binance's "you ignored a 429" ban — surfaces as FinanceError::RateLimited.

Next Steps#

built with cargo soothfast docs build source