Skip to content
DOCUMENTATION / Data API
OPBT SDK · 03

Data API

On this page
03

Data API

Every data API exposes only information available by the current simulation time and returns a pandas DataFrame indexed by UTC timestamps. Missing data raises DataNotPrefetched — check your universe and __data__ declaration.

history#

ctx.history(instrument, fields='close', window=100, freq=None) → DataFrame

The past window bars, ending at the last closed bar (the forming bar is never included). The UTC DatetimeIndex is named ts.

ParameterDefaultDescription
instrumente.g. binance:UPERP:BTCUSDT
fields'close'open/high/low/close/volume/quote_volume, string or list
window100number of bars
freqrun frequencymay be a coarser frequency (declared in extra_freqs)
ctx.history_many(instruments=None, fields='close', window=100, freq=None) → dict[str, DataFrame]

Read completed history for multiple instruments in one bounded call. Every returned frame uses the same UTC ts index as history.

ctx.klines(instrument, freq=None, lookback=100) → DataFrame

Canonical completed OHLCV + quote_volume K-lines in every mode, with a UTC ts index.

ctx.bbo(instrument) / ctx.orderbook(instrument) → BboSnapshot

Returns the current best bid and ask, not a full-depth order book. Backtest has no historical BBO archive, so it exposes the latest completed-bar close as a BAR_PROXY; this is useful for portable Strategy code but does not affect the separate backtest fill model. Paper and Live read a current OnePort BBO. Invalid or stale OnePort quotes are unavailable and cannot be used for an order.

funding_history#

ctx.funding_history(instrument, window=30) → DataFrame

Settled funding rates. Columns: rate (positive = longs pay shorts, normalized across venues), interval_hours (the venue's actual interval). Indexed by settlement time.

open_interest · liquidations#

ctx.open_interest(instrument, window=100) → DataFrame

Open interest (~5min sampling). Columns: oi and price. oi keeps the venue-native position_size unit and must not be compared or aggregated across venues. Cross-venue OI requires a future authoritative normalized API field; OPR never converts it downstream. Requires ‘oi’ in extra_freqs.

ctx.liquidations(instrument, window=500) → DataFrame

Liquidation events (tick-level, since 2025-04-18, 5 venues). Columns: price / qty / value / side. side is the venue's raw direction and is not normalized across venues; do not infer long- or short-liquidation direction from it. Requires ‘liq’ in extra_freqs.

Availability by execution mode#

SurfaceBacktestPaperLive
history · history_many · klinesUTC tsUTC tsUTC ts
bbo · orderbookBAR_PROXY · completed closeOnePort BBOOnePort BBO
ctx.accounts · order_status · open_ordersAvailableAvailableAvailable
OI · liq · snapshot · ticker · trade_flow · ADL historyHistorical onlyRejectedRejected

market_snapshots#

ctx.market_snapshots(instrument, window=168) → DataFrame

Hourly monitoring snapshots keyed by the venue's raw symbol. Nullable columns: bid_price / ask_price / mid_price, open_interest / open_interest_usd, volume_24h_usd_m, funding_rate_8h / funding_period_hours, next_funding_ts and oi_api_ts. Requires ‘snapshot’ in extra_freqs.

derivative_tickers#

ctx.derivative_tickers(instrument, window=1440) → DataFrame

The final received derivative-ticker observation for each UTC minute. Nullable columns: funding_ts / funding_rate / predicted_funding_rate, open_interest, last_price / index_price / mark_price. minute_ts is the source minute start; the index is the source receive time. Requires ‘ticker’ in extra_freqs.

trade_flow#

ctx.trade_flow(instrument, window=1440) → DataFrame

Completed one-minute trade aggregates. Columns: base_volume / quote_volume, taker_buy_base_volume / taker_sell_base_volume, taker_buy_quote_volume / taker_sell_quote_volume and trade_count. The index is minute_close_time, and a row becomes visible only at that close boundary. Requires ‘trade_flow’ in extra_freqs.

Properties#

ctx.nowcurrent simulation timestamp at bar close
ctx.universeinstrument tuple
ctx.frequencyrun frequency
ctx.paramscustom parameters passed at submission
ctx.statedurable finite-JSON state, max 256 KiB
ONEPORT RESEARCH · DOCUMENTATION