Bybit

Capabilities

  • Backfill: OHLC (full), order-book snapshot. No trades.

  • Stream: OHLC, trades, order book.

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

Note

Bybit spot exposes only the ~60 most recent trades and no history, so trades backfill raises NoCapability rather than returning a misleading recent slice. Live trades are available via the stream.

Symbols

BTCUSDT (no separator), spot category.

Example

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

API

class BybitSource(http=None)[source]

Bybit source adapter (spot + USDT-perpetual funding/open interest).

  • Backfill: OHLC (full), order-book snapshot, realized funding (linear perp market only), open interest (linear perp, full history back to symbol launch). No trades (see Notes).

  • Stream: OHLC, trades, order book.

See also

dccd.Client

the public facade.

Notes

Bybit spot exposes only the ~60 most recent trades and no history, so TradesHistory is deliberately not implemented — a trades backfill raises NoCapability rather than returning a misleading recent slice. Live trades are still available via the stream.

Funding history (GET /v5/market/funding/history) has two quirks: Bybit rejects a request carrying startTime without endTime (both must always be sent), and pages come back newest-first — the adapter walks backward, using each page’s oldest timestamp minus one millisecond as the next page’s endTime.

Open interest (GET /v5/market/open-interest) is span-typed (5min to 1d buckets via bybit_oi_interval) and, unlike funding, exposes a real nextPageCursor — it is passed through unchanged as the opaque cursor instead of being reconstructed from timestamps.

Examples

>>> from dccd.sources.bybit import BybitSource
>>> BybitSource().capability_for(DataType.TRADES, 'rest', 'historical') is None
True
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, walking backward from end_ns.

Bybit’s funding/history endpoint rejects a request that carries startTime without endTime — both are always sent. Pages are newest-first, so cursor (when set) is the previous page’s oldest timestamp minus 1 ms, reused as this call’s endTime; startTime stays pinned to start_ns throughout the walk. linear category only — this endpoint 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, following Bybit’s real cursor.

Unlike funding/history, open-interest returns a genuine result.nextPageCursor — it is passed through unchanged rather than reconstructed from timestamps. linear category only (no spot equivalent). Returns ([], None) when span has no bybit_oi_interval mapping.

async fetch_orderbook(symbol, depth)[source]

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

render_symbol(s)[source]

Render a canonical Symbol to this exchange’s string.

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/deltas over WebSocket.

stream_trades(symbol)[source]

Stream live trades over WebSocket.