> Every Taji docs page as Markdown: https://docs.taji.is/llms.txt

# Data: how the hub reads market data

Every bar, quote and headline Taji shows comes through one door, the hub (`engine/crates/taji-trading/src/hub.rs`). The window, your agent, charts and granted process plugins all read through one typed contract (`substrate/taji-brokerage/src/read.rs`) and one store on your machine, so two callers asking the same question get the same rows from the same source. This page explains how a read is routed, what it can see, where its rows are kept and what it refuses.

## How does a read reach the data?

```mermaid
flowchart LR
  clients["Window, agent, plugins"] --> wire["Wire: parse, set the Policy"]
  wire --> walk["Source walk: the pin, else the order"]
  walk --> held{"Store holds the span?"}
  held -->|"yes"| cut["Cut at at"]
  held -->|"gap, metered"| miss["409 fetch_first"]
  held -->|"gap, free"| vendor["Provider, through its gate"]
  vendor --> write["pulls.db, then taji.duckdb and catalog.db"]
  write --> cut
  cut --> ans["Answer: rows, source, cursor, missing"]
```

Read it from the left. A client sends `GET /get/<product>` on the wire (`engine/crates/taji/src/wire/data.rs`), which parses the words and sets the caller's `Policy`. The hub picks the providers that may answer, best first. It answers from the store where the store holds the span. For a gap, a metered provider (one that bills per call) refuses until you buy with `fetch`; a free one is called, and its answer is logged and written before it is read back. Every answer is cut at the read's instant `at`, so no row you could not have known then comes back.

## What does a read ask for?

A read names a product, a list of items and an instant. The product is a `DataProduct` word (`bars`, `quotes`, `news`, ...) or `series:<name>` for a dataset you registered. An item is `kind:text`, such as `equity:SPY`; a malformed one fails `400 bad_ask` before any routing. Items of different kinds mix in one read, each read under its own class. A vendor never appears in a product's name: it appears only as a pin, a provider the read names.

Four calls form the contract:

| Call | What it does |
|---|---|
| `get` (`Hub::get`) | History up to `at`, over `[from, to)` or the last `N` rows. Answers typed Arrow batches, or per symbol a `Miss` naming the gaps and what filling them costs |
| `stream` (`Hub::stream`) | Updates after `at`, in time order, within an equity session (`24h` covers all of them) |
| `held_spans` (`Hub::held_spans`) | What the store holds, per product, provider, symbol, interval and basis (`GET /held`) |
| `fetch` (`Hub::fetch`) | The only call that spends: it prices the gaps (`dry_run`) and buys only under `Policy::buy`, against your `data_budget` |

Each product has one schema (`read.rs`, `substrate/taji-brokerage/src/reference.rs`). Prices and quantities are `Decimal128(38,10)`. A vendor field that no column names is not served, so a second provider can always fill the same product ([0004](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0004-capabilities-through-the-hub.md)).

## Which provider answers?

One function decides, for every read: `engine/crates/taji-trading/src/hub/source.rs`. It lists the linked providers that serve the ask, best first, and the read walks that list, passing over a provider that has no source for it, is rate limited or errs. Nothing else routes.

A pin (`Policy::provider`) restricts the read to that one provider. It fails `not_linked` when the provider is not linked or its data is switched off, `vault_locked` when the vault holding its key is locked, and `not_served` when it does not serve the ask. With no pin, the eligible providers sort by these keys, in order:

| Key | Puts first |
|---|---|
| Live `24h` equity bars | A live feed before a delayed one, and overnight, one that is live overnight |
| Hotlist rank | For a hotlist ask, the provider's own rank of it |
| `Policy::prefer` | The provider the read prefers |
| `Ties::live_first`, streams only | The providers Taji's `Ties` (`engine/crates/taji-open/ties/src/lib.rs`) streams first |
| `link.prefer.data` | Your own list for the class, in its order |
| `Ties` names it | A provider Taji's build names, before one it does not |
| Rank | Your access tier, then `Ties`' order; for streams, pushed before polled |

The window and your agent read at the current instant. A chart's first load names the provider the class streams on, so history and live are one vendor's prints, unless your `link.prefer.data` names one (`first_named` in `engine/crates/taji/src/data/mod.rs`).

## Why does one answer carry one basis?

Providers serve an equity's bars on different bases: `raw`, `split`, `split-spinoff` or `split-dividend-spinoff`. A wrong basis reads exactly like a right one, so mixing them would show only as a wrong price. Every equity bar in one answer therefore shares one basis, chosen before routing: the one you asked for; else the pin's own; else `split-spinoff` where any ranked provider states it; else the first ranked provider's (`source::unasked_basis`). A provider that cannot serve that basis refuses `not_served`. Values stay as the vendor gives them ([0007](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0007-vendor-basis-as-given.md)).

Quotes at the current instant may be delayed rows. A stream that asks `live_only` refuses a delayed plan when it opens and lapses on the first delayed tick. A cursor from a single-provider read pins that provider; a composed read's cursor pins none.

## What can a read see at an instant?

Nothing knowable after `at`. A `to` past `at` is refused `400 lookahead`, and every row is cut by when it became knowable:

| Rows | Knowable at |
|---|---|
| Bars | Their end, or their session's close where that is sooner (`engine/crates/taji-trading/src/hub/store/knowable.rs`). A daily bar at its date's session close, early closes included |
| Reference rows | `knowable_utc`: the vendor's instant, else the next `America/New_York` midnight after their date, else when Taji first saw them (`reference.rs`). Earnings carry their report instant |
| Ticks, depth, status, imbalance, statistics | `ts_init` in nanoseconds, kept beside the vendor's `ts_event` |
| Registered datasets (`series:<name>`) | Their release instant (`release_at` in `engine/crates/taji-trading/src/hub/store.rs`), rounded up to the minute. A row whose time is missing or does not exist is withheld, never released early |

This read asks for SPY's daily bars from 25 November with `at` at 17:00 UTC on 27 November, the half day after Thanksgiving:

```json file="examples/data/past.json"
{
  "metadata": {
    "adjustment": "raw",
    "dataset_id": "bars:csv-source:SPY:D:raw",
    "provider": "{\"equity:SPY\":\"csv-source\"}",
    "source": "{\"equity:SPY\":\"store\"}",
    "timeframe": "D"
  },
  "rows": [
    {
      "symbol": "SPY",
      "provider": "csv-source",
      "start_dt": "2026-11-25T00:00:00+00:00",
      "knowable": "2026-11-25T21:00:00+00:00",
      "open": 137.31,
      "high": 140.3,
      "low": 136.39,
      "close": 139.53,
      "volume": 2000000,
      "vwap": null,
      "trade_count": null,
      "up_volume": null,
      "down_volume": null
    }
  ]
}
```

The 27 November bar is not there. Its session closed at 13:00 New York time, 18:00 UTC, an hour after `at`, so at 17:00 nobody could have known it. The 26th was a holiday and has no bar.

*Captured 2026-12-04 on a headless kernel reading a made-up daily series for SPY.*

## Where are the rows kept?

The store is three files under its root (`engine/crates/taji-trading/src/hub/store.rs`):

| File | Holds |
|---|---|
| `pulls.db` (SQLite, `store/pulls.rs`) | The money log and the raw answers. A fetch is logged `pending` at its expected cost, reserved against `data_budget`, before the vendor call; then its raw answer. Spend is the sum of `cost_usd` |
| `taji.duckdb` (DuckDB) | The typed rows. One bar series per provider, class, symbol, interval and basis, held at its tier (`1m`, `5m`, `30m`, `1h`, `4h` or `D`, `Interval::of`); a `15m` or `2h` read aggregates from its tier and is never stored. Registered datasets live here too |
| `catalog.db` (SQLite, `store/catalog.rs`) | What the store holds: the coverage reads trust |

One writer thread commits rows first, then the catalog, so a failed write leaves no coverage. A crash mid-fetch is safe: on open, `pending` pulls turn `lost` and keep their cost, an answer that would not parse is parsed again rather than bought twice, and `catalog::replay` applies every logged pull before the first read. The two derived files can be rebuilt from `pulls.db` with no vendor call. `Store::dump` (`store/dump.rs`) drops a dataset's rows and coverage and keeps its pulls and spend, logged in `pulls.db` first, so a rebuild does not bring it back and only a new ask buys it again.

A product a provider serves only at the current instant answers a past `at` from the newest stored answer at or before it, else `not_served`.

## What happens when you read the same bars twice?

The first read of SPY's last daily bar goes to the provider, here `csv-source` serving a made-up series:

```json file="examples/data/first.json"
{
  "metadata": {
    "adjustment": "raw",
    "dataset_id": "bars:csv-source:SPY:D:raw",
    "provider": "{\"equity:SPY\":\"csv-source\"}",
    "source": "{\"equity:SPY\":\"vendor\"}",
    "timeframe": "D"
  },
  "rows": [
    {
      "symbol": "SPY",
      "provider": "csv-source",
      "start_dt": "2026-12-03T00:00:00+00:00",
      "knowable": "2026-12-03T21:00:00+00:00",
      "open": 141.45,
      "high": 143.43,
      "low": 141.23,
      "close": 142.62,
      "volume": 5000000,
      "vwap": null,
      "trade_count": null,
      "up_volume": null,
      "down_volume": null
    }
  ]
}
```

`source` says `vendor`. The same read again comes from the store, with the same rows:

```json file="examples/data/again.json"
{
  "metadata": {
    "adjustment": "raw",
    "dataset_id": "bars:csv-source:SPY:D:raw",
    "provider": "{\"equity:SPY\":\"csv-source\"}",
    "source": "{\"equity:SPY\":\"vendor\"}",
    "timeframe": "D"
  },
  "rows": [
    {
      "symbol": "SPY",
      "provider": "csv-source",
      "start_dt": "2026-12-03T00:00:00+00:00",
      "knowable": "2026-12-03T21:00:00+00:00",
      "open": 141.45,
      "high": 143.43,
      "low": 141.23,
      "close": 142.62,
      "volume": 5000000,
      "vwap": null,
      "trade_count": null,
      "up_volume": null,
      "down_volume": null
    }
  ]
}
```

`GET /held` shows what the store now holds of SPY:

```json file="examples/data/held.json"
[
  {
    "product": "bars",
    "provider": "csv-source",
    "symbol": "equity:SPY",
    "timeframe": "D",
    "adjustment": "raw",
    "spans": [
      {
        "from": 1505672974,
        "to": 1796342400,
        "session": "regular"
      }
    ],
    "rows": 2318
  }
]
```

*Captured 2026-12-04 on a headless kernel reading a made-up daily series for SPY.*

The daily series reaches back to 2017: the hub stored more than the one row the read asked for, so a later read of any of it calls no one. Each entry is one series: its provider, timeframe and basis (`adjustment`), its spans, each with the session whose minutes it holds, and its row count.

## When does a read spend money?

Only through `fetch`. A `get`, and every read the window or your agent makes, never buys from a metered provider: an uncovered span answers `409 fetch_first`, a `Miss` priced by `dry_run`. `fetch` reserves the cost against `data_budget` before it calls, so two buys gated at once never pass the ceiling together. `store_only` answers from the store alone.

A gap is fetched once. A read claims the gap's pieces, and a second reader of the same pieces waits for them, then asks for the rest. A claimed piece lands even when the reader that claimed it goes away (`dropped_waiter_fetch_lands` in `engine/crates/taji-trading/src/hub/tests.rs`). A provider that is rate limited part way returns what it stored and when to ask again (`rest_after`).

## How do several providers make one series?

An unpinned bars read of one instrument with two or more members (ranked providers, plus providers the store already holds it from) is composed (`engine/crates/taji-trading/src/hub/compose.rs`). Each instant goes to the best-ranked member that holds it, and no timeframe bar is split between two. A narrower session (`regular`, `extended`) feeds its minutes into a wider view (`24h`).

Gaps are fetched from the best members at once. On interactive and live lanes (`engine/crates/taji-plugin/src/vendor/gate.rs`), a member silent for 5 s (`FIRST_PAGE`) lets the next one start too, and the first rows win. A member that answers no rows is passed over for that span alone.

Where two members meet, the join is checked against stored bars: the median OHLC difference must stay within 0.2% (`SEAM_PRICE`), zero-volume bars skipped except on indexes. A join is checked again only after a write. A rejected join refetches the staler side once; still rejected, the read refuses `409 seam` and the chart stops there. A member on another basis joins only while the symbol's held `corporate_actions` show no separating action from the read's start to its instant (`source::equity_basis`).

## How does a chart keep its series whole?

A chart reads through a `Series` (`engine/crates/taji-trading/src/hub/series.rs`): the held spans plus an in-memory span of the live 1m stream. It finds gaps on events (a read landing, a stream break, the first close), never on a timer, and asks for each gap once, and again at the first close once the provider holds through its end. A gap it cannot fill is reported as `SeriesEvent::Gaps`. The window's chart corpus is separate from the store and never feeds a hub read.

## How are news, earnings and search joined?

Unpinned `corporate_actions`, `earnings`, `ipos`, `news` and `search` reads union their providers' rows by exact key, filling each field group from providers in that group's order, after the cut at `at` (`engine/crates/taji-trading/src/hub/join.rs`, `products.rs`). A search waits at most 1 s on the extra providers, or takes the first to answer with `first`. At the current instant, a union read answers from the store and refreshes behind you once per freshness window (`tail_fresh`: 5 min for `news`, 15 min for `earnings`, 1 h for `corporate_actions`); `wait`, `store_only` or a past instant reads inline. Tick spans and option chains stitch by `America/New_York` day.

## How do live bars and ticks arrive?

One upstream per provider, product, symbol and timeframe fans out to every consumer in the kernel (`hub.rs`, `engine/crates/taji-trading/src/hub/feed.rs`, `stream.rs`), because a vendor subscription is scarce. Bar relays subscribe to 1m bars and fold coarser intraday bars from them.

A bar arrives `Closed`, and `Forming` while it builds if you ask. A window closes on the vendor's close, a later frame, or the kernel clock at its end plus 2 s (`CLOSE_GRACE_S`) and the plan's delay. Only the vendor marks a close `confirmed`, or, where a source sends no explicit closes, the next window's frame after it watched the window whole; a clock close never is. A source outside its hours sends `Shut` without ending the stream. A dead upstream is `Lapsed` to everyone attached and is never restarted on its own: asking again opens a fresh one.

An unserved continuous future streams and charts the contract it trades as (`trades_as`, `engine/crates/taji-trading/src/hub/contracts.rs`), reopening at each roll. A quote's `session` is the vendor's, never the clock's; its day figures are the kernel's (`hub/read.rs`).

Ticks are best effort. An upstream keeps its newest 128 rows (`TICK_DEPTH` in `hub/stream.rs`); a consumer further behind resumes at the oldest kept row, after a `Lost` update counting the prints it missed.

## Who may read through the hub?

| Caller | What it gets |
|---|---|
| Window and agent | Every product over the wire. The kernel computes each figure with trading meaning (ratios, surprises, day changes, session labels, seam checks, pushed views in `engine/crates/taji/src/views/mod.rs`), so clients only scale, format and draw ([0001](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0001-kernel-computes.md)) |
| Process plugins | One read door, `get/<product>`, bounded by their manifest's `[grants] reads` and `[[sources]]` ([Manifest](https://docs.taji.is/plugins/manifest.md)) |
| Vendors | Nothing above the hub. Vendor clients and credentials live behind `Hub` and its gate, held by `engine/crates/taji-trading/tests/dependency_audit.rs` ([0005](https://github.com/TajiAI/Taji/blob/main/docs/decisions/0005-no-key-reaches-a-client.md)) |

A read-through ask (`trades`, `quotes`, `depth`) is never stored. It joins an identical ask already in flight unless it says `refresh`, and a landed answer is not reused (`joined` in `hub/products.rs`). `trades`, `quotes`, `depth`, `economic`, `filing_sections`, full-text `filings`, symbol and directory `holdings` and plugin products never write to `taji.duckdb`, and no last-value quote cell exists.

## Which refusals can a read answer?

| Code | Status | When |
|---|---|---|
| `bad_ask` | 400 | A malformed item or word |
| `lookahead` | 400 | `to` past `at` |
| `fetch_first` | 409 | A gap only a metered provider can fill |
| `seam` | 409 | A join past 0.2% after one refetch |
| `vault_locked` | 409 | A pinned provider's key is in a locked vault |
| `not_linked` | 422 | A pinned provider is not linked, or its data is off |
| `rate_limited` | 429 | The provider is rate limited; `rest_after` says when to ask again |
| `not_served` | 501 | No linked provider serves the ask, or not on its basis |

Every code and its status is `schema Code` in `schema/wire.json` ([Wire](https://docs.taji.is/reference/wire.md)).

## What is not built yet?

- Trade corrections and retractions are not typed on `trades` rows.
- Store writes land asynchronously. A reader beside a queued write sees only landed rows and may fetch the span again (`identical_gets_beside_a_queued_write_fetch_twice` in `hub/tests.rs`), except a `Series` reader, whose `Landed` overlay tracks its queued bars.
- Stream backfill (`StreamAsk::since_utc`) is refused as `bad_ask`: read the span, then stream.

## See also

- [Wire](https://docs.taji.is/reference/wire.md): every route, its words and its refusals.
- [Read bars over the wire with curl](https://docs.taji.is/cookbook/wire-read-bars.md): the first call above, from your own shell.
- [Add a data source](https://docs.taji.is/plugins/source.md): a provider of your own behind the hub.
- [Write a compiled-in provider](https://docs.taji.is/plugins/provider.md): a data source or brokerage built into the kernel.
- [Coverage](https://docs.taji.is/reference/coverage.md): which provider serves which product.
- [Architecture](https://docs.taji.is/architecture/overview.md): processes, clients, boundaries.
