Binance

The reference adapter — full historical depth and every live channel.

Capabilities

  • Backfill: OHLC (klines, 1 000/req), trades (aggTrades, cursor-paginated by fromId), order-book snapshot (depth, ≤ 5 000).

  • Stream: OHLC (kline), trades (aggTrade), order book (depth).

  • OHLC fidelity: quote_volume ✅ native · trades ✅ native.

Symbols

BTCUSDT (no separator) — pass BTC/USDT to dccd.

Example

async with Client() as c:
    await c.backfill("binance", "BTC/USDT", "ohlc", span=3600, start="2024-01-01")
    await c.backfill("binance", "BTC/USDT", "trades", start="2024-01-01")

API

class BinanceSource(http=None)[source]

Binance source adapter (spot + USDS-M futures OHLC, funding, open interest).

The reference adapter — full historical depth and every live channel.

  • Backfill: OHLC (klines, 1 000/req), trades (aggTrades, cursor-paginated by fromId), order-book snapshot (depth, ≤ 5 000), realized funding rate (USDS-M fundingRate, perp market only), open-interest statistics (USDS-M openInterestHist, perp only — Binance serves at most the last 30 days, hence history="recent" + recent_window_s; run a recurring job to accumulate history forward).

  • Stream: OHLC (kline), trades (aggTrade), order book (depth).

  • Derivative OHLC: a non-spot market (perp, quarter, next_quarter) routes fetch_ohlc_page to the USDS-M futures continuousKlines endpoint instead of spot klines — no live futures channels are declared (WS caps stay spot-only).

Adapters are not used directly — they are resolved by the engine from the registry. Drive them through dccd.Client or the CLI.

See also

dccd.Client

the public facade.

dccd.sources.registry.SourceRegistry

adapter resolution.

Examples

>>> from dccd.sources.binance import BinanceSource
>>> sorted({c.data_type.value for c in BinanceSource().capabilities()})
['funding', 'ohlc', 'open_interest', 'orderbook', 'trades']
capabilities()[source]

Declared capabilities, one per (data type × transport × mode).

async fetch_funding_page(symbol, start_ns, end_ns, limit, cursor=None)[source]

Fetch one page of realized funding rates (cursor = next startTime in ms).

First call (cursor=None) is time-bounded on start_ns; subsequent calls advance startTime to the last event’s fundingTime + 1 ms. USDS-M futures only — fundingRate has no spot equivalent.

async fetch_ohlc_page(symbol, span, start_ns, end_ns, limit)[source]

Fetch one page of OHLC bars (see fetch_ohlc_page).

async fetch_oi_page(symbol, span, start_ns, end_ns, limit, cursor=None)[source]

Fetch one page of open-interest statistics (cursor = next startTime in ms).

USDS-M openInterestHist — ascending pages, walked forward like fetch_funding_page: the first call (cursor=None) anchors on start_ns, then each page advances startTime to the last observation’s timestamp + one span. Two quirks of the real endpoint (verified 2026-07-04) shape the request:

  • Binance serves only the last 30 days (declared as history="recent") and returns HTTP 400 for a startTime at or beyond the rolling boundary — so startTime is floored to the window (re-evaluated at request time, with a safety margin).

  • When the requested window holds more than limit observations, Binance returns the latest ones in it, not the earliest — so each request’s endTime is bounded to the page capacity (limit slots) and the continuation signal is window left, not page fullness.

Returns ([], None) without a request when span has no supported period mapping (only {5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d}) or when the whole window predates the 30-day floor.

async fetch_orderbook(symbol, depth)[source]

Fetch a current order-book snapshot up to depth levels.

async fetch_trades_page(symbol, start_ns, end_ns, limit, cursor=None)[source]

Fetch one page of aggregate trades (cursor = fromId).

First call (cursor=None) is time-bounded on start_ns; subsequent calls follow the fromId cursor. The next cursor is the last aggregate-trade id + 1, returned only while the page is full and the last trade is still inside the window.

render_symbol(s)[source]

Binance format: BTCUSDT (no separator).

stream_ohlc(symbol, span)[source]

Stream live OHLC bars over WebSocket.

stream_orderbook(symbol, depth, *, min_interval=0.0)[source]

Stream live order-book snapshots over WebSocket.

Uses Binance’s partial book depth stream, which pushes a fully sorted top-N snapshot — N is clamped to the supported {5, 10, 20}.

stream_trades(symbol)[source]

Stream live trades over WebSocket.