Market LabDocs
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().open

Open Positions

ctx.positions().open contains main-account positions for declared symbols. Pass a configured name to read a subaccount instead:

ctx.positions("trading-2").open

Analysis-only jobs return an empty list.

Common fields:

FieldMeaning
idStable local position identity.
symbolNormalized symbol.
sidelong or short.
entry_priceAverage entry price.
mark_priceCurrent reference price.
notionalCurrent notional value.
marginAllocated margin.
leveragePosition leverage for perpetuals.
qtyBase quantity.
unrealized_pnlCurrent unrealized PnL.
realized_pnlRealized PnL when available.
feesAccrued fees when available.
fundingAccrued funding when available.

Backtest positions can also include simulated timestamps, protection prices, events_held, and reason.

Record references:

On this page