Sources

One adapter per exchange, each implementing the fine-grained Source protocols and declaring its Capability set. The engine resolves an adapter from the registry; you drive them through dccd.Client.

For each exchange’s capabilities, quirks and adapter class, see the per-exchange pages.

Adding an exchange

Implement the relevant protocol mixins below and a capabilities() method, then register the adapter in build_registry.

Registry

class SourceRegistry[source]

Maps exchange names to source adapter instances.

Examples

>>> reg = SourceRegistry()
>>> # reg.register('binance', BinanceSource())
>>> # src = reg.get_ohlc_history('binance')
property adapters

Read-only view of all registered adapters keyed by exchange name.

Used by dccd.Client to enter/exit every adapter’s HTTP client in a single async with block, keeping one pool alive for the lifetime of the context.

property exchanges

Names of all registered exchanges.

get(exchange)[source]

Return the adapter registered for name (raises NoCapability if absent).

get_ohlc_history(exchange)[source]

Return name as an OHLCHistory or raise NoCapability.

get_ohlc_live(exchange)[source]

Return name as an OHLCLive or raise NoCapability.

get_orderbook_live(exchange)[source]

Return name as an OrderBookLive or raise NoCapability.

get_orderbook_snapshot(exchange)[source]

Return name as an OrderBookSnapshotREST or raise NoCapability.

get_trades_history(exchange)[source]

Return name as a TradesHistory or raise NoCapability.

get_trades_live(exchange)[source]

Return name as a TradesLive or raise NoCapability.

register(exchange, adapter)[source]

Register an adapter for an exchange.

resolve(exchange, data_type, transport, mode)[source]

Return appropriate adapter or raise NoCapability.

Source protocols

Source protocols — fine-grained per (data_type × mode).

class OHLCHistory[source]

Bases: Source

Protocol: can fetch historical OHLC pages via REST.

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

Fetch up to limit OHLC bars of span seconds in [start_ns, end_ns].

class OHLCLive[source]

Bases: Source

Protocol: can stream live OHLC bars via WebSocket.

stream_ohlc(symbol, span)[source]

Yield live OHLC bars of span seconds over WebSocket.

class OrderBookLive[source]

Bases: Source

Protocol: can stream live order book snapshots/deltas via WebSocket.

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

Yield live order-book snapshots over WebSocket.

Parameters:
symbolSymbol
depthint

Maximum number of levels per side to include in each snapshot.

min_intervalfloat, optional

Minimum seconds between emitted snapshots. 0.0 (default) preserves the legacy per-frame behaviour — every WS frame yields a snapshot. Pass snapshot_interval from the job spec to move the throttle upstream so pydantic objects are only constructed for frames that will actually be saved.

class OrderBookSnapshotREST[source]

Bases: Source

Protocol: can fetch an order book snapshot via REST.

async fetch_orderbook(symbol, depth)[source]

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

class Source[source]

Bases: object

Base mixin for all source adapters.

Adapters inherit from Source and one or more capability protocols. They declare capabilities and render exchange-specific symbol strings.

capabilities()[source]

Return list of declared capabilities.

capability_for(data_type, transport, mode)[source]

Return the declared Capability for this combination, or None.

property http_client

Return the adapter’s shared AsyncHTTPClient.

REST adapters store their client in self._http and return it here so callers (e.g. backfill) can hold the context open for an entire multi-page operation — keeping _depth >= 1 across pages so no TCP/TLS re-handshake occurs between pages.

WebSocket-only adapters return None (default).

render_symbol(s)[source]

Render a canonical Symbol to the exchange-specific string.

class TradesHistory[source]

Bases: Source

Protocol: can fetch historical trade pages via REST.

Cursor contract: fetch_trades_page returns (trades, next_cursor). The cursor is an opaque, adapter-defined string used to continue inside the [start_ns, end_ns) window:

  • cursor=None on the first call — anchor on start_ns (or end_ns for adapters that page backward).

  • next_cursor is None when the window is exhausted (the adapter returned a short/last page, or the next item would fall outside the window). Returning a non-None cursor tells the paginator to call again.

This lets the generic paginator drain a window completely — fixing the capped-single-page data loss that affected every liquid pair — without per-exchange chunking in the application layer.

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

Fetch one page of trades; return (trades, next_cursor) (see class).

class TradesLive[source]

Bases: Source

Protocol: can stream live trades via WebSocket.

stream_trades(symbol)[source]

Yield live trades over WebSocket.

default_http_client(exchange)[source]

Build an AsyncHTTPClient wired to the limiter.

REST adapters call this to construct their default shared client so that every outbound request is throttled by the process-wide per-exchange shared_limiter. Keeping the wiring here (rather than in each adapter) means a single seam controls proactive rate-limiting for all exchanges.

Parameters:
exchangestr

Exchange name used to key the limiter bucket.

Returns:
AsyncHTTPClient