Skip to main content
data is a BarData object passed to handle_data, scheduled callbacks and before_trading_start. Every read is async and returns a Polars DataFrame with date, sid and the fields you asked for.

Current values

await data.current(assets, fields, data_source=None)

The latest available values at the current simulation time.
For several assets, map rows back by sid:

Historical windows

await data.history(assets, bar_count=None, frequency=timedelta(days=1), fields=None, data_source=None, since=None)

A trailing window ending before the current bar, adjusted for splits and dividends as of the current simulation time. Pass exactly one of bar_count or since:
  • bar_count — a number of rows. On bar data that is a number of sessions.
  • since — a span of calendar time, such as since=datetime.timedelta(days=90). Event datasets usually want this: thirty congressional disclosures for one ticker can span four years.
Because the window excludes the current bar, read the current value separately when the signal needs it:
Ask for enough bars to warm every indicator up, and return early when the window is short:

Returns across a universe

await data.returns(assets, bar_count, field="close", data_source=None)

What each asset returned over the last bar_count bars, as {listing: last / first - 1}. One history read serves the whole universe. Listings that can’t answer — not trading yet, no data, all zeros — are simply absent.

Fields

Custom sources expose their own fields. Name the source with data_source:
data_source also accepts a mounted dataset or an address such as "hf://ZipLime/congress-trading/features" — see Point-in-Time Datasets. Extensions can register their own address schemes; zipfinam adds algopack:// for MOEX AlgoPack.

Working with Polars

.iloc, .loc, .at and .iat don’t exist on a Polars frame. Use df["close"][-1], df["close"].to_numpy(), df["close"].mean(), or call .to_pandas() explicitly.

Futures

A continuous future is a data specifier. Ordering one raises.

Tradability

data.can_trade(assets)

Returns a pandas Series of booleans indexed by asset. An asset can trade when it is listed and not yet delisted or auto-closed, is not restricted, and its venue is open. Since 2.11.0 the venue check uses the listing’s own venue calendar: on a daily run it asks whether the venue traded that day; on an intraday run, whether it is open that minute. See Venues & Calendars.
can_trade is synchronous and does not check that a price exists. Read the price with data.current before ordering, and skip the asset when it is missing or zero.

Data clock helpers