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

# Draw an order-flow heatmap with trade bubbles and cumulative delta

The Order flow plugin turns a symbol's book and tape into a liquidity heatmap behind the candles, bubbles of trades, best bid and ask lines, the resting book at the chart's right edge and a cumulative delta pane; you play its generated sample and read the same rows over the wire.

You need Taji built from source (`cargo build -p taji-open`) and the plugin built in its own directory. No keyless source serves a book, so `taji plugin dev` plays the plugin's own recording, `plugins/taji-orderflow/fixtures/`, as if it were live; the example's `dev` file has the capture do the same:

```sh
(cd plugins/taji-orderflow && cargo build)
target/debug/taji plugin dev plugins/taji-orderflow
```

> [!IMPORTANT]
> Everything below is that recording: five minutes of an ES-like book and tape for `future:ESZ26` around 5,000, generated by `plugins/taji-orderflow/fixtures/gen.py` and played in a loop. The chart says so with its **Taji replay** tag. It is not live data, and its prices are not the market's.

`plugin dev` opens a desk with chart 1 on `future:ESZ26`'s 1-minute candles and the plugin's four layers and its `cvd` script bound. `calls.json` then reads three of the plugin's products and frames the chart; `{depth.[0].ts_utc}` stands for the first answer's `ts_utc`, so each later read and the frame are counted from the heatmap column `depth` returned:

```json file="examples/orderflow-heatmap/calls.json" title="calls.json"
[
  {"name": "depth", "method": "GET", "route": "/get/taji-orderflow.depth?symbols=future:ESZ26", "until": "length >= 1"},
  {"name": "zoom", "method": "POST", "route": "/verb/desk/{desk}/chart/set_visible_range", "body": {"from": "{depth.[0].ts_utc / 60 | floor * 60 - 300}", "to": "{depth.[0].ts_utc / 60 | floor * 60 - 60}"}},
  {"name": "prints", "method": "GET", "route": "/get/taji-orderflow.prints?symbols=future:ESZ26&from={depth.[0].ts_utc + 40}&to={depth.[0].ts_utc + 70}", "until": "length >= 1"},
  {"name": "delta", "method": "GET", "route": "/get/taji-orderflow.delta?symbols=future:ESZ26&from={depth.[0].ts_utc + 40}&to={depth.[0].ts_utc + 70}", "until": "length >= 1", "shot": true}
]
```

![The replayed ESZ26 1-minute chart, zoomed to a few minutes: a liquidity heatmap of coloured cells behind and after the candles, trade bubbles over it, a dashed ask line at 5,000.25 and a solid bid line at 5,000.00, the resting book as bars at the right edge, and a Cumulative delta pane below falling to -345](https://raw.githubusercontent.com/TajiAI/Taji/main/docs/cookbook/examples/orderflow-heatmap/shot.png)

1. **`depth`** reads `GET /get/taji-orderflow.depth`: with no span, the newest row, one second's column of the heatmap. A plugin's product is read at `/get/<plugin id>.<product>` like any data product. The plugin stores its rows only once a binding streams the symbol, so the first read can come back empty; `until` repeats it until a row is there.
2. **`zoom`** sends `set_visible_range` to chart 1 so a few minutes fill the pane, instead of the hours the chart opens on, where a few minutes of heatmap are a sliver at the right edge. `from` and `to` are UTC seconds and must lie on candles the chart has loaded, so `to` is the minute before the column's.
3. **`prints`** reads the prints of the 30 seconds starting 40 seconds after that column. `from` and `to` are UTC seconds; seconds that have not played yet have no rows, so `until` repeats the read until the first print is there, and the answer holds the prints played up to that moment.
4. **`delta`** reads the delta rows from the same second, one per second with prints. `shot` photographs the chart after it, once 40 seconds more of the recording have played, so the heatmap has columns to draw.

The heatmap column, one second of the book: `price` runs up in `step`s of 0.25 and `value` is each price's peak resting size in that second, both sides together:

```json file="examples/orderflow-heatmap/depth.json"
[
  {
    "ts_utc": 1796330837,
    "ts_ms": 1796330837000,
    "span_ms": 1000,
    "step": 0.25,
    "price": [
      4998,
      4998.25,
      4998.5,
      4998.75,
      4999,
      4999.25,
      4999.5,
      4999.75,
      5000,
      5000.25,
      5000.5,
      5000.75,
      5001,
      5001.25,
      5001.5,
      5001.75,
      5002,
      5002.25,
      5002.5,
      5002.75
    ],
    "value": [
      108.0,
      26.0,
      2000.0,
      24.0,
      308.0,
      143.0,
      127.0,
      29.0,
      30.0,
      111.0,
      29.0,
      61.0,
      40.0,
      108.0,
      52.0,
      33.0,
      13.0,
      57.0,
      73.0,
      24.0
    ],
    "levels": null,
    "venues": null,
    "knowable_utc": 1796330838,
    "recorded": true,
    "version": "0.1.0"
  }
]
```

- The column covers 20 prices, 4,998.00 to 5,002.75, bids and asks together.
- The 2,000 at 4,998.50 is the recording's bid wall, a large bid that rests there for all five minutes.
- `levels` and `venues` are `null`: `plugin dev` plays the book with no `scope`, which states them.
- `knowable_utc`, `recorded` and `version` are the kernel's on every plugin row: when the row could first be read, that it came from the kernel's record of the product, and the plugin version that computed it.

The prints played by the time the read was answered, here one:

```json file="examples/orderflow-heatmap/prints.json"
[
  {
    "ts_utc": 1796330880,
    "ts_ms": 1796330880485,
    "price": 5000,
    "size": 12.0,
    "side": -1,
    "knowable_utc": 1796330880,
    "recorded": true,
    "version": "0.1.0"
  }
]
```

- Each row is one trade: its `price`, its `size` in contracts and its `side`, `1` where the buyer crossed the spread and `-1` where the seller did. This one is 12 contracts sold at 5,000.00. The tick rule estimates the side where the feed does not state it, so the plugin marks `side` `estimated`.
- On the chart the prints that fall within 8 pixels of each other in price and time are one bubble, sized by their total and its ring split into the buyers' share and the sellers'; the smallest bubbles in view are not drawn.

The delta row of that second:

```json file="examples/orderflow-heatmap/delta.json"
[
  {
    "ts_utc": 1796330880,
    "buy": 0.0,
    "sell": 12.0,
    "unknown": 0.0,
    "delta": -12.0,
    "gap": 0,
    "knowable_utc": 1796330881,
    "recorded": true,
    "version": "0.1.0"
  }
]
```

- `delta` is `buy` minus `sell` in the second: the 12 sold make it -12. `unknown` is the size whose side neither the feed nor the tick rule could set, and `gap` the rows the feed dropped.
- The `cvd` script sums `delta` per candle and restarts at each session's first candle: that is the Cumulative delta pane, at -345 when the picture was taken.

`zoom` answers the node it changed:

```json file="examples/orderflow-heatmap/zoom.json"
{
  "node": "desk/01a23da7-0e33-75d4-95b4-7c47b4fbc0f8/chart/view",
  "seq": 1796330687414816
}
```

*Captured 2026-12-03 on `taji plugin dev plugins/taji-orderflow --headless`, playing the plugin's generated `fixtures/`.*

## Use it on a real book

The plugin reads the `depth` and `trades` that Taji already streams, for stocks, futures and crypto. The depth row of [Data coverage](https://docs.taji.is/reference/coverage/data.md) names which provider streams a live book for each class: TradeStation and Interactive Brokers for futures; TradeStation, Robinhood, Interactive Brokers and Schwab for stocks; Alpaca and Interactive Brokers for crypto. Databento serves depth as history only. The prints and the delta need that class's live `trades` too, in its `trades` row.

## Change it

Read the resting book at a second's close instead of the heatmap column, bids positive and asks negative:

```diff
-  {"name": "depth", "method": "GET", "route": "/get/taji-orderflow.depth?symbols=future:ESZ26", "until": "length >= 1"},
+  {"name": "depth", "method": "GET", "route": "/get/taji-orderflow.book?symbols=future:ESZ26", "until": "length >= 1"},
```

Read the best bid and ask at each second's close from the same second, the two lines on the chart:

```diff
-  {"name": "delta", "method": "GET", "route": "/get/taji-orderflow.delta?symbols=future:ESZ26&from={depth.[0].ts_utc + 40}&to={depth.[0].ts_utc + 70}", "until": "length >= 1", "shot": true}
+  {"name": "bbo", "method": "GET", "route": "/get/taji-orderflow.bbo?symbols=future:ESZ26&from={depth.[0].ts_utc + 40}&to={depth.[0].ts_utc + 70}", "until": "length >= 1", "shot": true}
```

Get an alert when cumulative delta crosses zero, as the plugin's skill does:

```diff
-  {"name": "delta", "method": "GET", "route": "/get/taji-orderflow.delta?symbols=future:ESZ26&from={depth.[0].ts_utc + 40}&to={depth.[0].ts_utc + 70}", "until": "length >= 1", "shot": true}
+  {"name": "delta", "method": "GET", "route": "/get/taji-orderflow.delta?symbols=future:ESZ26&from={depth.[0].ts_utc + 40}&to={depth.[0].ts_utc + 70}", "until": "length >= 1", "shot": true},
+  {"name": "watch", "method": "POST", "route": "/verb/desk/{desk}/watches/add", "body": {"symbol": "future:ESZ26", "when": "crosses", "of": {"indicator": {"name": "cvd", "params": {}, "plot": "cvd"}}, "price": 0}}
```

## Next

- [Order flow](https://docs.taji.is/catalog/taji-orderflow.md): each product's rows, how the side is estimated, and the limits.
- [Build a feature plugin](https://docs.taji.is/plugins/feature.md): write a plugin like this one, its fixtures and `taji plugin dev`.
- [Data coverage](https://docs.taji.is/reference/coverage/data.md): which provider serves which data, for each class.
