Market LabDocs
ScriptingData Types

Data Types

Data shapes available inside Market Lab scripts.

Data Types

Market records are retained by exact selector and read through the third hook argument:

export function onData(ctx, input, history) {
  const candles = history.source('candles@binancef@mmt')
  const book = history.source('orderbook@bulk', 0)
  const oi = history.source('oi@binancef@mmt', 0)
}

Calling without an index returns a frozen list ordered oldest to newest. With an index, 0 returns the newest record and 1 the previous record.

input contains metadata instead of a second copy of source data:

input.source
input.source_type
input.provider
input.exchange
input.symbol
input.source_configs
input.positions.open

Source configuration is keyed by exact selector:

input.source_configs['candles@binancef@mmt'].timeframe_sec
input.source_configs['orderbook@bulk'].depth

Script params are flat:

ctx.params.fast
ctx.params.max_spread_bps

Positions

Live runs and backtests pass the current position for the script symbol at input.positions.open. Analysis-only jobs return an empty list. BULK uses one-way positions, so the list normally contains zero or one item.

type OpenPosition = {
  id: string
  order_id?: string
  side: 'long' | 'short'
  entry_ts_ms?: number
  entry_price: number
  mark_ts_ms?: number
  mark_price: number
  notional: number
  margin: number
  leverage: number
  qty: number
  stop_loss_price?: number
  take_profit_price?: number
  unrealized_pnl: number
  realized_pnl?: number
  liquidation_price?: number
  fees?: number
  funding?: number
  events_held?: number
  reason?: string
}

Backtest positions include the simulated timestamps, protection prices, events_held, and reason. Live BULK positions include realized PnL, liquidation price, fees, and funding.

Available source pages:

On this page