Scripting V2 - PythonPlain Python Files
Data Types
Normalized market records and runtime state available to Python V2.
Python V2 receives normal dictionaries and lists:
candles = history.source("btc@candles@binancef:timeframe=60")
book = history.source("btc@orderbook@bulkf:depth=20", 0)
trade = history.source("btc@trades@bulkf", 0)
oi = history.source("btc@oi@binancef@mmt:timeframe=60", 0)Without an index, records are ordered oldest to newest. With an index, 0 is newest and 1 is previous.
The hook context describes the source rather than duplicating its record:
ctx.source
ctx.source_type
ctx.provider
ctx.exchange
ctx.symbol
ctx.source_configs
ctx.positions().openOpen Positions
ctx.positions().open contains main-account positions for declared symbols. Pass a configured name to read a subaccount instead:
ctx.positions("trading-2").openAnalysis-only jobs return an empty list.
Common fields:
| Field | Meaning |
|---|---|
id | Stable local position identity. |
symbol | Normalized symbol. |
side | long or short. |
entry_price | Average entry price. |
mark_price | Current reference price. |
notional | Current notional value. |
margin | Allocated margin. |
leverage | Position leverage for perpetuals. |
qty | Base quantity. |
unrealized_pnl | Current unrealized PnL. |
realized_pnl | Realized PnL when available. |
fees | Accrued fees when available. |
funding | Accrued funding when available. |
Backtest positions can also include simulated timestamps, protection prices, events_held, and reason.
Record references: