History
Read bounded Python V2 source history without future data.
Every exact source selector has its own retained buffer.
Retained Records
records = history.source("btc@candles@binancef:timeframe=60")The list is ordered oldest to newest. An unknown selector or empty buffer returns [].
Returned dictionaries and lists are copies. Changing them does not modify Market Lab's internal history.
Indexed Records
latest = history.source("btc@candles@binancef:timeframe=60", 0)
previous = history.source("btc@candles@binancef:timeframe=60", 1)
missing = history.source("btc@candles@binancef:timeframe=60", 99)Index 0 is newest and 1 is previous. An unavailable index returns None. Indexes must be non-negative integers.
Retention
The manifest's lookback sets capacity independently for every exact selector:
script = {
"name": "lead-lag",
"version": "2",
"lookback": 200,
}The effective range is 2 to 5,000 records, with 5,000 as the default. lookback is a capacity, not a preload request.
Live jobs begin with empty buffers. Backtests begin at --from. Always check that enough records exist:
candles = history.source("btc@candles@binancef:timeframe=60")
if len(candles) < 21:
returnMultiple Sources
BTC = "btc@candles@binancef:timeframe=60"
ZEC = "zec@candles@binancef:timeframe=60"
def on_data(ctx, history):
if ctx.symbol != "btc":
return
btc = history.source(BTC, 0)
zec = history.source(ZEC, 0)
if btc is None or zec is None:
returnBacktests merge configured sources into timestamp order. A record enters history immediately before its own on_data call, so future records are never visible. Configured source order breaks same-timestamp ties.
Candle-like updates with the same timestamp replace the current record instead of shifting the buffer. Index 1 therefore remains the previous completed period.
See Sources for selectors and Data Types for record shapes.