Market data
Candles, quotes, whole spans of history, bar lines, warm-up, news and index members.
bars = while25.candles("EQ:US:AAPL", "5m", limit=200) # newest 200, LIVE series
old = while25.historical("EQ:US:AAPL", "1D", # a real vendor pull
start="2024-01-01")
today = while25.intraday("EQ:US:AAPL", "5m") # today, from the vendor
q = while25.quote("EQ:US:AAPL") # None if unknowncandles(..., source=) picks which store the bars come from, and the three
are different questions rather than fallbacks for one another:
source | Reads | Raises when |
|---|---|---|
"live" (default) | the in-memory series a chart or @on.bar is filling — never fetches | NO_SERIES, when nothing is watching that symbol and interval yet |
"historical" | a real vendor pull, cached; intraday intervals within a bar budget (below) | NO_DATA / BAD_RANGE |
"intraday" | today's bars from the vendor, no cache | UNSUPPORTED_INTERVAL outside 1m/5m/15m/30m/1h |
An interval While25 does not know ("7m") is refused UNKNOWN_INTERVAL
on every source, never read as another. An indicator does not call
candles() at all: it receives the chart's own series as while25.bars
(see Indicators), and source="live" inside compute() raises
LIVE_IN_COMPUTE, because a second series drifts from the one drawn under
the plot with nothing to notice. "live" is for a strategy or an app reading
the series a chart, or its own @on.bar line, is filling. An analysis script
with no chart open wants "historical"; a backtest wants history_span()
(below), which has no bar budget.
start/end are ISO dates and apply to "historical" only. start is
honoured: While25 walks as many vendor requests as the range takes, back
to the history floor (2012) and, for an intraday interval, within a budget of
25,000 bars counted back from end. A start it could not reach is logged on
the module as a warning naming the date the answer really starts from, and
the rows carry it as .effective_start and why as .note ("" when the answer
covers the window). The budget is this call's limit, never the vendor's depth:
history_span() fetches every bar of the window. The rows also carry .session
("regular" or "full") and .adjustment ("raw", "split", or None
where the vendor states nothing — never read None as raw). A data call that
gets no answer within 30 seconds raises TimeoutError.
while25.history(...) still works and is exactly candles(..., source="live").
(while25.data.* is the same surface under its namespace.)
It is deprecated: the name promised a fetch it never performed, which is what
made people expect vendor data from it.
quote() returns None when the platform has no data for that symbol — 0.0
is a real price, and a strategy that cannot tell "no data" from "worthless"
will act on the difference.
A quote carries symbol, ltp, bid, ask, open, high, low,
prev_close, volume, time (the venue's stamp), as_of (when While25
last saw data for it) and market_open (True, False, or None when it
cannot say); every figure is None until seen, never 0. ltp is the last
TRADED price: None until the instrument has traded in what the platform
holds, even when it already has a bid and an ask for it. quotes([...])
answers one entry per symbol asked, in that order, None where there is no
data.
A candles(source="historical") call whose vendor fetch fails raises
IO_ERROR with the vendor's failure, even when earlier bars are cached: they
are never handed back as the answer the vendor did not give. Ask again.
A whole span of history
candles(source="historical") reads what the vendor serves in one call. For a
whole span, every bar between two dates, use history_span():
r = while25.history_span("EQ:US:AAPL", "5m", "2024-01-02", "2024-06-28")
bars = r["bars"] # the rows candles() returns, plus "regular"
r["missing_days"] # ["2024-03-11", ...]: trading days with no barThe interval is one of 1m, 5m, 15m, 30m, 1h, 1D, 1W, 1M; the
other spellings While25 takes (1d, 1440, DAILY, 60, ...) come back
under that name.
While25 fetches exactly that window on a worker of its own, request by
request at the vendor's pace (a chart always goes first), with no cap that cuts
it short. Nothing is cached on disk: a window that has fully closed (its end
before the exchange's today) is kept in memory for While25's session, and
the same span asked again comes back from it with r["vendor_requests"] == 0
and a line in r["vendor_notes"] that says "served from memory". A window
still open is fetched every time. A refusal comes back in the vendor's own
words, as a While25Error with While25's code (TOO_WIDE, VENDOR_PACING,
PERMISSION, NOT_SUPPORTED, ...). It BLOCKS until the span is in, which takes
minutes on a paced vendor: call it from on_start, a schedule or a one-shot
run, never from a tick handler. Each request shows in the module's log
(history EQ:US:AAPL 5m: fetching history, part 3 of about 12; waiting, a chart is loading its history first while charts go first; waiting its turn, 2 fetches ahead while another module's fetch or a backtest runs — While25 fetches
one span at a time), and a Stop of the module stops the fetch (CANCELLED).
One span at a time per module: a second call while one is under way is
refused BUSY. A span that reports nothing for 180 seconds is given up
(TIMEOUT), and so is one still running after 30 minutes. A walk the vendor
stopped short raises with the vendor's words; its partial bars are not
returned.
hours="eth" and adjust="split" work as on candles(); so does price="mark"
(a Binance USD-M futures contract's mark candles, no volume; UNSUPPORTED_PRICE
elsewhere; left out, the last trade). The answer also
says session, adjustment, covered_from / covered_to (the dates it
covers), first_bar_ms (the first bar's time; None with no bars),
vendor, vendor_requests, vendor_notes (stretches the vendor said
held nothing) and calendar, the exchange calendar the instrument trades on
("XNYS", "XBOM", "CMES", "24/7"; "" when none is known).
missing_days lists the finished trading days of that calendar inside the
covered dates that have no bar: whole days only, None when no calendar is
known. Weekly and monthly series are not checked.
A span cut short (TOO_WIDE mid-walk, VENDOR_PACING, a vendor refusal) raises
While25Error whose .answer holds the partial answer: the bars it got, with
covered_from / covered_to, to inspect. It has no id, so a backtest can
never be sealed on it. If the call outlives its 30-minute wait it raises a plain
TimeoutError instead and the walk is cancelled at While25.
Bars: a bar line the module keeps
from while25 import Bars, Strategy, on
class Breakout(Strategy):
id = "breakout"
aapl = Bars("EQ:US:AAPL", "5m", keep=200)
@on.bar(aapl)
def on_bar(self, ctx, bar):
high = max(self.aapl.closes[:-1]) # the 199 closes before this bar
...Bars(symbol, interval, *, hours=None, keep=200) declares a bar line on the
class and keeps its bars:
- It is the line's subscription: no separate
@on.bar(symbol, interval). - At start it holds its last
keepfinished bars beforeon_startruns, fetched by a warm-up with every check under "Warm-up" below. A refusal fails the start with its reason. - Each closed bar is added before any handler runs, and the oldest dropped
past
keep.
keep: 1 to 10,000. hours="eth": the full session. Intervals: 1m, 5m, 15m,
30m, 1h, 1D, 1W, 1M; another is refused when the file is saved (use
@on.bar(symbol, interval) and keep the bars yourself). @on.bar(line)
wakes a handler on the line's bars; with no handler the line is still kept,
for a tick handler to read. Any kind of module may declare lines.
On the module, self.aapl is the line:
self.aapl.rows | the bars, oldest first, each as an @on.bar handler receives it |
self.aapl.last | the newest finished bar, None before there is one |
self.aapl.closes | every bar's close, oldest first |
len(self.aapl), self.aapl[-1], for bar in self.aapl | as on a list |
self.aapl.indicator(cls, *, forming=False, **params) | an indicator worked out from these bars (see "An indicator's numbers in a strategy") |
Read rows; While25 writes it.
Warm-up: the history a strategy decides from
A Bars line does all of this for you. warmup() is the same fetch by hand,
for a module that keeps its bars in its own way:
class Breakout(Strategy):
id = "breakout"
def on_start(self, ctx):
bars = while25.warmup("EQ:US:AAPL", "5m", 200) # the 200 bars before now
self.closes = [b["close"] for b in bars]
@on.bar("EQ:US:AAPL", "5m")
def on_bar(self, ctx, bar):
self.closes.append(bar["close"]) # carries on from the warm-up
...A strategy that computes on bars (a 20-bar average, an RSI) needs the bars
before its first one. warmup(symbol, interval, bars, hours=None) gives the
last bars finished bars of one of the strategy's own @on.bar lines,
written as the line writes them (hours="eth" for an "eth" line); with no
such line it raises ValueError. Intervals: 1m, 5m, 15m, 30m, 1h, 1D, 1W,
1M; bars 1 to 10,000. To have an indicator do the computing, hand it these
bars: see "An indicator's numbers in a strategy".
It is fetched the way a backtest's history is — While25's history service, no cache, the vendor's own refusal — back from now until it holds the bars, and checked before it is handed on:
- Every trading day is there. A trading day of the instrument's exchange
calendar with no bar inside the warm-up refuses (
MISSING_DAYS, naming the days); a weekly or monthly line, a whole week or month. An instrument with no exchange calendar known has days nobody can check, and refuses too (NO_CALENDAR). - Nothing unfinished. A bar still forming is left out.
- Enough of it. Fewer than
barsfinished bars refuses (NOT_ENOUGH_HISTORY, saying how many there are) — after one wider fetch, since how far back the first may go is worked out before the calendar is known. - It joins the live bars. Where the line's live series and the warm-up
both hold bars, they are the same bars (
WARMUP_JOINnames the first live bar the history lacks: another bar grid, or a bar the vendor lost), and no bar that finished before the line was attached is missing from both (WARMUP_JOIN: the vendor had not published it yet — deploy again in a moment).
Call it in on_start: the strategy reads starting until it returns, and
nothing of it runs meanwhile. On an intraday line it first waits until 15
seconds after the line was attached, so the vendor has published the bar
that finished as the strategy started (that bar is never delivered live).
Each vendor request shows in the module's log,
and so in the last-log cell of its row in Live strategies; a Stop stops the
fetch, and the strategy ends stopped. Let a refusal raise: the start fails
with the reason, and the strategy never decides on history nobody checked.
The vendor's own codes come through as on history_span() (TOO_WIDE,
VENDOR_PACING, PERMISSION, TIMEOUT, CANCELLED, ...), and one span runs
at a time per module, a history_span() included (BUSY).
The rows have an @on.bar bar's keys — symbol, interval, hours,
time_ms, open, high, low, close, volume — so one piece of code can
read both, and the list carries .session, .adjustment, .vendor and
.calendar. A live bar the warm-up already gave (one that finished while it
fetched) is not delivered to the line's handlers again. The first live bar
after it is checked once more against the live series; a bar between the two
that reached the strategy neither way halts it with the reason (phase
warmup) before the handler runs.
News
rows = while25.news("EQ:US:AAPL", start="2026-08-01", limit=20) # oldest first
rows.truncated # True: the page cap was hit, older articles may exist
rows.errors # {instrument_key: "FAILED" | "PARTIAL"}: a vendor fetch that fell overnews(symbols, start=, end=, source=, limit=) answers from the same news
path the platform's news panel reads. symbols is one symbol or a list of up
to 10; start / end are ISO dates or epoch milliseconds, end inclusive to
the end of its day; source names one outlet; limit caps articles per
symbol (50 by default, 200 at most). Each row has symbol, time_ms,
title and url always, and author, excerpt, body, source,
sentiment, sentiment_score, ... only when the vendor sent them (an absent
field is an absent key), plus in_market_hours (True / False / None).
With no news vendor configured it raises NO_PROVIDER rather than returning
an empty list. @on.news("EQ:US:AAPL") delivers each live article the same
way, one handler call per article; with no news vendor the line is accepted
and never fires.
Index members
while25.universes() # ["banknifty", "ndx100", ...]
while25.universe("ndx100") # [{"symbol", "name", "canonical_id"}, ...]
while25.universe_info("ndx100") # index, name, country, as_of, source, countDated reference data from the platform's own constituent registry, read from
a file with no round trip. An index it does not hold raises ValueError
naming the ones it does — never an empty list.