Binance¶
The reference adapter — full historical depth and every live channel.
Capabilities¶
Backfill: OHLC (
klines, 1 000/req), trades (aggTrades, cursor-paginated byfromId), 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 byfromId), order-book snapshot (depth, ≤ 5 000), realized funding rate (USDS-MfundingRate,perpmarket only), open-interest statistics (USDS-MopenInterestHist,perponly — Binance serves at most the last 30 days, hencehistory="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) routesfetch_ohlc_pageto the USDS-M futurescontinuousKlinesendpoint instead of spotklines— 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.Clientor the CLI.See also
dccd.Clientthe public facade.
dccd.sources.registry.SourceRegistryadapter resolution.
Examples
>>> from dccd.sources.binance import BinanceSource >>> sorted({c.data_type.value for c in BinanceSource().capabilities()}) ['funding', 'ohlc', 'open_interest', 'orderbook', 'trades']
- async fetch_funding_page(symbol, start_ns, end_ns, limit, cursor=None)[source]¶
Fetch one page of realized funding rates (cursor = next
startTimein ms).First call (
cursor=None) is time-bounded onstart_ns; subsequent calls advancestartTimeto the last event’sfundingTime+ 1 ms. USDS-M futures only —fundingRatehas 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
startTimein ms).USDS-M
openInterestHist— ascending pages, walked forward likefetch_funding_page: the first call (cursor=None) anchors onstart_ns, then each page advancesstartTimeto 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 astartTimeat or beyond the rolling boundary — sostartTimeis floored to the window (re-evaluated at request time, with a safety margin).When the requested window holds more than
limitobservations, Binance returns the latest ones in it, not the earliest — so each request’sendTimeis bounded to the page capacity (limitslots) and the continuation signal is window left, not page fullness.
Returns
([], None)without a request when span has no supportedperiodmapping (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 onstart_ns; subsequent calls follow thefromIdcursor. 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.