Core Concepts

Data Sources

All available market data feeds — OHLCV, funding, liquidations, options, ETF flows, and more.

Data sources are timeseries feeds you open with source(...) (or via the dedicated function for some sources). Every script needs at least one. Most scripts open ohlcv; specialized indicators reach for the others.

Opening data sources
timeseries ohlcvData = source("ohlcv", currentSymbol, currentExchange);
timeseries funding = source("funding_rate", currentSymbol, currentExchange);

Data Access Methods

kScript v2 provides two ways to access market data.

Use dedicated functions for each data source — cleaner and more readable, with better compile-time checking:

Direct function
timeseries trade = ohlcv(currentSymbol, currentExchange);

2. Universal source() Function

Use the general source() function with a data type parameter. More dynamic, but the string identifier isn't checked until runtime:

source() function
timeseries trade = source("ohlcv", currentSymbol, currentExchange);

Some sources expose dedicated functions that take additional parameters:

Dedicated function with custom params
// Treasury balance is keyed by asset, not symbol/exchange
timeseries treasuryBalance = binance_treasury_balance(asset="BTC");

// Equivalent via source()
timeseries treasuryBalance = source("binance_treasury_balance", asset="BTC");

Available Data Sources

kScript provides access to a wide range of data sources covering price data, derivatives, options, lending markets, and institutional flows.

Market data

SourceDescription
ohlcvOpen, High, Low, Close, Volume bars. The default chart feed.
orderbookLive bid/ask depth — feed the _* orderbook functions (sumBids, sumAsks, etc.).
buy_sell_volumeVolume split by aggressor side.
liquidationsForced-liquidation events.
funding_ratePerpetual funding rates with predicted values.
open_interestOpen interest series.
long_short_ratioLong/short positioning ratios across all traders, top trader accounts, and top trader positions. Available for Binance, Bybit, and OKX.
cme_oiCME open interest. Only available for BTC and ETH.

Options & volatility

SourceDescription
options_volumePuts and calls volume from Binance Options or Deribit. Limited to BTC and ETH.
options_open_interestPuts and calls open interest from Binance Options or Deribit. Limited to BTC and ETH.
deribit_implied_volatilityImplied volatility on Deribit. Returns 1W / 1M / 3M tenors. BTC and ETH only.
deribit_volatility_indexDeribit DVOL volatility index (OHLC). BTC and ETH only.
skew% difference in IV between call and put options on Deribit. Deltas 15 and 25; tenors 1W / 1M / 3M. BTC and ETH only.

ETF, treasury & DeFi

SourceDescription
etf_flowETF inflow/outflow data. Only available on 1D intervals.
etf_holdingAsset balance held by major BTC, ETH, and SOL ETFs.
etf_premium_rateETF premium/discount to NAV. BTC, ETH, and SOL ETFs.
binance_treasury_balanceValue of assets held by Binance, updated monthly. Available for BTC, ETH, SOL, USDT, USDC.
ethena_positionsAmount of collateral within the Ethena protocol.

Data Source Categories

Data sources are organized into categories based on the type of market information they provide.

CategoryDescriptionSources
Price & VolumeCore market data including price, volume, and orderbook dynamicsohlcv, buy_sell_volume, orderbook
Derivatives & FuturesFutures, perpetuals, and derivative market metricsfunding_rate, liquidations, open_interest, cme_oi, long_short_ratio
Options & VolatilityOptions data, implied volatility, and skew metricsoptions_volume, options_open_interest, deribit_implied_volatility, deribit_volatility_index, skew
Institutional & ETFETF flows, institutional holdings, and treasury dataetf_flow, etf_holding, etf_premium_rate, binance_treasury_balance
Protocols & DeFiProtocol-specific metrics and DeFi positionsethena_positions

Calling source()

Most data sources are opened with source(name, symbol, exchange):

Calling source()
timeseries ohlcvData = source("ohlcv", currentSymbol, currentExchange);
timeseries fundingData = source("funding_rate", currentSymbol, currentExchange);
timeseries liquidationData = source("liquidations", currentSymbol, currentExchange);

Aligning multiple sources

When mixing feeds (e.g. liquidations on top of OHLCV), align timestamps with matchTimestamp:

Aligning multiple sources
timeseries ohlcvData = source("ohlcv", currentSymbol, currentExchange);
timeseries liquidationData = source("liquidations", currentSymbol, currentExchange);

timeseries alignedLiquidations = matchTimestamp(liquidationData, ohlcvData, "contains");

Match modes:

  • "exact" — exact timestamp match
  • "closest" — nearest timestamp
  • "contains" — bar contains the source timestamp (default for sub-bar events like liquidations)

Common Usage Patterns

Examples of how to use different data sources in your trading strategies.

Basic Price Data

Access OHLCV data for price-based technical analysis.

Price Analysis
//@version=2

define("Price Analysis", "onchart", true);

// Method 1: Direct function (recommended)
timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange);

// Method 2: Using source() function
// timeseries trade = source("ohlcv", currentSymbol, currentExchange);

// Calculate simple moving average on close prices
var sma20 = sma(trade, 20, 4);

plotLine(value=sma20, width=2, colors=["blue"], label=["SMA 20"], desc=["20-period Simple Moving Average"]);

Funding Rate Analysis

Monitor funding rates across perpetual futures markets.

Funding Rate Monitor
//@version=2

define("Funding Rate Monitor", "offchart", true);

// Method 1: Direct function (recommended)
timeseries funding = funding_rate(symbol=currentSymbol, exchange=currentExchange);

// Method 2: Using source() function
// timeseries funding = source("funding_rate", currentSymbol, currentExchange);

// Plot funding rate
var width = input("width", "number", 2);

plotLine(value=funding, width=width, colors=["blue", "green", "red"], label=["Funding Rate"], desc=["Funding Rate Data"]);

Liquidation Monitoring

Track liquidation events and volumes for market sentiment.

Liquidation Tracker
//@version=2

define("Liquidation Tracker", "offchart", true);

// Method 1: Direct function (recommended)
timeseries liquidationData = liquidations(symbol=currentSymbol, exchange=currentExchange);

// Method 2: Using source() function
// timeseries liquidationData = source("liquidations", currentSymbol, currentExchange);

// Plot liquidations as bars
plotBar(value=liquidationData, width=1, colors=["green", "red"], label=["Liquidations"], desc=["Liquidation Data"]);

Best Practices

Choose Appropriate Sources
Select data sources that match your strategy timeframe and requirements. For example, etf_flow only updates on 1D intervals, so it's not suitable for intraday strategies.
Cache Data References
Store data source references to avoid repeated function calls.
timeseries trade = ohlcv(currentSymbol, currentExchange);
var fastMA = sma(trade.close, 10);
var slowMA = sma(trade.close, 20);
Handle Data Availability
Not all data sources are available for every symbol/exchange combination. For example, funding rates only exist for perpetual futures contracts, options data is only available on exchanges that offer options trading, and cme_oi is restricted to BTC and ETH. When data is unavailable, the timeseries will contain na values.