# Data Types (/scripting/data-types)



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

```js
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:

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

Source configuration is keyed by exact selector:

```js
input.source_configs['btc@candles@binancef@mmt'].timeframe_sec
input.source_configs['btc@orderbook@bulkf'].depth
```

Script params are flat:

```js
ctx.params.fast
ctx.params.max_spread_bps
```

## Positions [#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.

```ts
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:

* [Candles](/scripting/data-types/candles)
* [Orderbook](/scripting/data-types/orderbook)
* [Trades](/scripting/data-types/trades)
* [VD](/scripting/data-types/vd)
* [Open Interest](/scripting/data-types/oi)
* [Volumes](/scripting/data-types/volumes)
