Skip to main content

data-sources.source#

Declare a data dependency at the top of the script.

SYNTAX#

source(kind: 'ohlcv'|'oi'|'funding'|'liquidations'|'orderbook', opts?: { symbol?: string, exchange?: string, interval?: string, timeframe?: string, limit?: number }): SourceHandle

ARGUMENTS#

  • kind ('ohlcv' | 'oi' | 'funding' | 'liquidations' | 'orderbook') — Which data feed to pre-fetch. Each kind maps to a different upstream API.
  • opts.symbol (string) — Symbol override (e.g. 'ETHUSDT'). Defaults to the chart's symbol.
  • opts.exchange (string) — Exchange override (e.g. 'bybit'). Defaults to the chart's exchange.
  • opts.interval (string) — Candle interval ('1m', '1h', '1D'). Defaults to the chart's interval. Alias: timeframe.
  • opts.limit (number) — Maximum number of bars/points. Defaults to the chart's series length.

RETURNS#

SourceHandle — { kind, shape: 'series'|'snapshot', values?: { time, ...kind-specific arrays }, payload?: any, data: <full payload> }. For per-candle kinds, values.<field>[i] aligns 1:1 with candles[i] (NaN where data is unavailable). For snapshot kinds, read .payload.

EXAMPLE#

// @indicator { name: "OHLCV from BTC", overlay: true }
const btc = source("ohlcv", { symbol: "BTCUSDT", exchange: "binance" });
function onBar(i, ctx) {
  // Read the pre-fetched, time-aligned close at the same bar index.
  plot("btc-close", btc.values.close[i]);
}