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.
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.
1. Direct Functions (Recommended)
Use dedicated functions for each data source — cleaner and more readable, with better compile-time checking:
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:
timeseries trade = source("ohlcv", currentSymbol, currentExchange);Some sources expose dedicated functions that take additional parameters:
// 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
| Source | Description |
|---|---|
ohlcv | Open, High, Low, Close, Volume bars. The default chart feed. |
orderbook | Live bid/ask depth — feed the _* orderbook functions (sumBids, sumAsks, etc.). |
buy_sell_volume | Volume split by aggressor side. |
liquidations | Forced-liquidation events. |
funding_rate | Perpetual funding rates with predicted values. |
open_interest | Open interest series. |
long_short_ratio | Long/short positioning ratios across all traders, top trader accounts, and top trader positions. Available for Binance, Bybit, and OKX. |
cme_oi | CME open interest. Only available for BTC and ETH. |
Options & volatility
| Source | Description |
|---|---|
options_volume | Puts and calls volume from Binance Options or Deribit. Limited to BTC and ETH. |
options_open_interest | Puts and calls open interest from Binance Options or Deribit. Limited to BTC and ETH. |
deribit_implied_volatility | Implied volatility on Deribit. Returns 1W / 1M / 3M tenors. BTC and ETH only. |
deribit_volatility_index | Deribit 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
| Source | Description |
|---|---|
etf_flow | ETF inflow/outflow data. Only available on 1D intervals. |
etf_holding | Asset balance held by major BTC, ETH, and SOL ETFs. |
etf_premium_rate | ETF premium/discount to NAV. BTC, ETH, and SOL ETFs. |
binance_treasury_balance | Value of assets held by Binance, updated monthly. Available for BTC, ETH, SOL, USDT, USDC. |
ethena_positions | Amount of collateral within the Ethena protocol. |
Data Source Categories
Data sources are organized into categories based on the type of market information they provide.
| Category | Description | Sources |
|---|---|---|
| Price & Volume | Core market data including price, volume, and orderbook dynamics | ohlcv, buy_sell_volume, orderbook |
| Derivatives & Futures | Futures, perpetuals, and derivative market metrics | funding_rate, liquidations, open_interest, cme_oi, long_short_ratio |
| Options & Volatility | Options data, implied volatility, and skew metrics | options_volume, options_open_interest, deribit_implied_volatility, deribit_volatility_index, skew |
| Institutional & ETF | ETF flows, institutional holdings, and treasury data | etf_flow, etf_holding, etf_premium_rate, binance_treasury_balance |
| Protocols & DeFi | Protocol-specific metrics and DeFi positions | ethena_positions |
Calling source()
Most data sources are opened with source(name, symbol, exchange):
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:
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.
//@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.
//@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.
//@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
etf_flow only updates on 1D intervals, so it's not suitable for intraday strategies.timeseries trade = ohlcv(currentSymbol, currentExchange);
var fastMA = sma(trade.close, 10);
var slowMA = sma(trade.close, 20);cme_oi is restricted to BTC and ETH. When data is unavailable, the timeseries will contain na values.