Feeds as inputs

View as MarkdownOpen the editor

A feed is a series published on OpenMarket under an address, @scope/name: an air quality reading every hour, a city's temperature, a daily total.

An indicator reads a feed like any other source (Data sources): one input declaration, read in onBar() through in_<name>(), lined up on the chart's own bars.

Declaring a feed

text
input("close", ohlcv.close);                                                  // the chart's own candles: the bars
input("aqi", series.value, { ref: "@perceptlabs/kl-aqi", missing: "carry" }); // the feed, by its address
PartWhat it is
series.valueThe feed's reading: its first value key.
refThe feed's address, @scope/name. Required.
missing"carry" (the default) repeats the last reading on a bar without one; "nan" leaves that bar empty.

The sheet records the input as { "source": "series", "field": "value", "ref": "@perceptlabs/kl-aqi", "missing": "carry" }. A feed is never the first input: the chart's own candles come first and set the bars every reading lands on.

How readings land on bars

  • A bar reads the last reading published inside it, on the chart's interval in UTC.
  • Under "carry", a bar with no reading repeats the last one, and the reading just before the loaded window seeds the first bars.
  • Under "nan", a bar with no reading reads NaN and draws nothing: the right policy for events, where a quiet bar means nothing happened.
  • A feed that publishes faster than the chart's bars shows its last reading per bar; a slower one carries between readings, or leaves gaps under "nan".

Where a feed is read

WhereWhat it reads
The chart@scope/name feeds, on 1m, 5m, 15m, 30m, 1h, 4h, 1D and 1W charts
OpenMarket's cloudthe same feeds, for an indicator running there
Your OpenMarket runnerthe same feeds, plus watch/<slug>/<key>, a series one of your watches keeps

Refusals

The chart names the reason before it fetches anything:

The chart saysBecause
feeds read on 1m, 5m, 15m, 30m, 1h, 4h, 1D and 1W chartsthe chart's interval is not one feeds are read on
a watch series reads on your OpenMarket runnerthe ref is a watch/<slug>/<key> series
state feeds are not numericthe feed publishes states, not numbers
has no readings yetnothing has been published to the feed so far

Starting points

The template picker's Feeds group holds three complete indicators (The editor):

CardReadsDraws
Feed with an alert line (feed-alert-line)@perceptlabs/kl-aqithe feed as a line, an alert line at a level you set, the feed shaded above it and a mark on each cross up
Feed events as labeled dots (feed-events)@perceptlabs/usgs-quakesa faint column per reading and a labeled dot on every reading from a smallest value up
Feed status card (feed-status-card)@perceptlabs/nyc-temperaturea card with the last reading, how long ago it changed and whether the feed is live, lagging or stale

Change ref to read another feed; the rest of the file follows it.