Market LabDocs

Data Types

Data shapes available inside Market Lab scripts.

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

export function onData(ctx, input, history) {
  const candles = history.source('btc@candles@binancef@mmt')
  const book = history.source('btc@orderbook@bulkf', 0)
  const oi = history.source('btc@oi@binancef@mmt', 0)
  const trade = history.source('btc@trades@bulkf', 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['btc@candles@binancef@mmt'].timeframe_sec
input.source_configs['btc@orderbook@bulkf'].depth

Script params are flat:

ctx.params.fast
ctx.params.max_spread_bps

Positions

Live runs and backtests pass current positions for every declared symbol at input.positions.open. Analysis-only jobs return an empty list. Current execution venues use one-way net positions, so the list normally contains zero or one item per symbol.

type OpenPosition = {
  id: string
  symbol: 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 venue positions can include realized PnL, liquidation price, fees, and funding.

Available source pages:

On this page