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

# Stream live quotes over the wire

This script opens your own Taji's market socket, asks for live quotes of SPY, and prints the first four frames that come back: a greeting, then rows of quotes and a status for SPY, in the order the kernel has them.

You need a running Taji, and Python with `websockets` 14 or later and `pyarrow` (`pip install websockets pyarrow`). Without a linked brokerage the quotes are Yahoo's: free, and labelled by Yahoo as delayed.

Run the script:

```sh
STATE="$HOME/Library/Application Support/Taji"
PORT=$(cat "$STATE/wire-port") TOKEN=$(cat "$STATE/wire-token") python3 - <<'PY'
import json, os
from websockets.sync.client import connect
import pyarrow as pa

ask = {"type": "stream", "id": "q1", "product": "quotes", "symbols": ["equity:SPY"], "session": "regular"}
with connect(f"ws://127.0.0.1:{os.environ['PORT']}/ws/market", additional_headers={"x-taji-token": os.environ["TOKEN"]}) as ws:
    ws.send(json.dumps(ask))
    for _ in range(4):
        frame = ws.recv()
        n = int.from_bytes(frame[:4], "little")
        print(json.loads(frame[4:4 + n]))
        if len(frame) > 4 + n:
            print(pa.ipc.open_stream(frame[4 + n:]).read_all().to_pylist())
PY
```

1. **`STATE`, `wire-port`, `wire-token`** are as in [Read bars over the wire with curl](https://docs.taji.is/cookbook/wire-read-bars.md): the state dir, the port the kernel listens on, and this launch's token.
2. **`/ws/market`** is the wire's market-data WebSocket. It takes the token in the `x-taji-token` header of the upgrade request, so no auth message follows; a wrong token is a 401 before the socket opens. A socket refuses a foreign `Origin`; this script sends none.
3. **`ask`** is the one message you send, as text JSON. `product` is `quotes`; `symbols` are items, each `kind:text`; `id` is your own name for the subscription, and every frame about it carries it back. An equity's quotes stream requires `session`, which keeps the ticks whose time falls in that session: `regular` is 09:30 to 16:00 ET. Without it the answer is an `error` frame, 400 `bad_ask`.
4. **`n`** is the frame's layout. Every frame the kernel sends is binary: a 4-byte little-endian header length, the header as JSON, then, only where the frame has rows, an Arrow IPC stream of one batch.
5. **`frame[4:4 + n]`** is the header, always decoded: its `type` says what the frame is, and `seq` counts the frames on this socket from 0.
6. **`frame[4 + n:]`** is the Arrow stream, decoded by `pyarrow` to rows when the frame has any. The prices arrive as `Decimal128`: Python prints them as `Decimal`, and the harness's JSON below as numbers.

The same frames as the harness decoded them, each `{"header", "rows"?}`:

```json file="examples/wire-stream-quotes/frames.json"
[
  {
    "header": {
      "type": "hello",
      "seq": 0
    }
  },
  {
    "header": {
      "type": "rows",
      "id": "q1",
      "history": false,
      "seq": 1
    },
    "rows": [
      {
        "symbol": "SPY",
        "ts": "2026-12-04T18:58:42.315433+00:00",
        "ts_init": 1796410722315433000,
        "provider": "samplefeed",
        "delayed": false,
        "halted": null,
        "session": null,
        "bid": 142.3,
        "ask": 142.32,
        "last": null,
        "bid_size": null,
        "ask_size": null,
        "book_ts": null,
        "last_ts": null,
        "last_exchange": null,
        "last_conditions": [],
        "prev_close": 142.62,
        "change": null,
        "change_pct": null,
        "session_close": null,
        "session_change": null,
        "session_change_pct": null,
        "market_session": "regular",
        "next_session": "post",
        "next_at": "2026-12-04T21:00:00+00:00"
      }
    ]
  },
  {
    "header": {
      "type": "status",
      "id": "q1",
      "symbol": "equity:SPY",
      "provider": "samplefeed",
      "liveness": "live",
      "delay_s": null,
      "last_tick_utc": null,
      "session": null,
      "adjusted": null,
      "prev_close": "142.62",
      "error": null,
      "code": null,
      "seq": 2
    }
  },
  {
    "header": {
      "type": "rows",
      "id": "q1",
      "history": false,
      "seq": 3
    },
    "rows": [
      {
        "symbol": "SPY",
        "ts": "2026-12-04T18:58:43.317684+00:00",
        "ts_init": 1796410723317684000,
        "provider": "samplefeed",
        "delayed": false,
        "halted": null,
        "session": null,
        "bid": 142.3,
        "ask": 142.32,
        "last": null,
        "bid_size": null,
        "ask_size": null,
        "book_ts": null,
        "last_ts": null,
        "last_exchange": null,
        "last_conditions": [],
        "prev_close": 142.62,
        "change": null,
        "change_pct": null,
        "session_close": null,
        "session_change": null,
        "session_change_pct": null,
        "market_session": "regular",
        "next_session": "post",
        "next_at": "2026-12-04T21:00:00+00:00"
      }
    ]
  }
]
```

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

- **`hello`**, `seq` 0, is the kernel greeting the socket. It carries only `seq`.
- **`status`** says how the subscription for one symbol stands, and comes again whenever that changes. Here `provider` is `samplefeed`, the capture's made-up source, and `liveness` is `live`. A feed that arrives late reads `delayed` with `delay_s` set; this one reads `live`, and `delay_s` is `null`. `prev_close` is yesterday's close as a decimal string, `"142.62"`, or `null` until the kernel has read it. `session`, `adjusted` and `last_tick_utc` are `null` here.
- **`rows`** carries the quotes, `history` `false`: a quotes stream has no history, only the newest row for each symbol since the last frame, then another frame on each later tick. These are SPY's, rows of `GET /get/quotes`' schema. `bid` and `ask` are the book's top, 142.30 and 142.32; `last`, the print, is `null` because this source streams a book and no prints (Yahoo's carries prints only, so there `bid` and `ask` are `null` instead). `change` and `change_pct`, `last` less `prev_close` and that over `prev_close` in percent, are `null` with it. `market_session` is `regular`, and `next_session` is `post` at `next_at`, 21:00 UTC, the close at 16:00 ET.
- **`delayed`** is `false`. A vendor may label its feed late (Yahoo says 15 minutes), but Taji does not take that word: it sets `delayed` from each tick, `true` when the tick's own time is over 60 s behind when Taji received it (`ts_init`, in nanoseconds). Read this flag, not the vendor's label, to know whether a price is current.

## Change it

Ask for two symbols. The kernel sends a `status` for each and one `rows` frame with both rows, so read six frames to get past them:

```diff
-ask = {"type": "stream", "id": "q1", "product": "quotes", "symbols": ["equity:SPY"], "session": "regular"}
+ask = {"type": "stream", "id": "q1", "product": "quotes", "symbols": ["equity:SPY", "equity:QQQ"], "session": "regular"}
```

```diff
-    for _ in range(4):
+    for _ in range(6):
```

Keep the pre- and post-market ticks as well. Outside 09:30 to 16:00 ET, a `regular` stream waits for a tick that is in the session, so use `extended`:

```diff
-ask = {"type": "stream", "id": "q1", "product": "quotes", "symbols": ["equity:SPY"], "session": "regular"}
+ask = {"type": "stream", "id": "q1", "product": "quotes", "symbols": ["equity:SPY"], "session": "extended"}
```

Read the quotes once instead of subscribing. A `get` message takes any `GET /get/<product>` product with its query string and answers one `rows` frame, `cursor` `null`, so read two frames, the greeting and the answer:

```diff
-ask = {"type": "stream", "id": "q1", "product": "quotes", "symbols": ["equity:SPY"], "session": "regular"}
+ask = {"type": "get", "id": "g1", "product": "quotes", "query": "symbols=equity:SPY"}
```

## Next

- [Wire](https://docs.taji.is/reference/wire.md): listeners, token scopes, refusals, and every WebSocket feed.
- [Read bars over the wire with curl](https://docs.taji.is/cookbook/wire-read-bars.md): the same token on a plain HTTP read.
- [Configuration](https://docs.taji.is/reference/configuration.md): the state dir and every file in it.
