> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Order flow

> Read every trade with its side, its taker order and its change in open interest, and sum the tape into per-bar values.

Build order flow from the tape: every taker fill on the market, with what 0xArchive records about it. `trades()` reaches back to the start of the UTC day before yesterday, from 0xArchive's history, and continues live from the chart's tape.

## A trade

| Field | What it is |
| - | - |
| `time`, `price`, `size`, `notional` | When, at what price, how much in the market's coin, and in USD |
| `side` | The taker's side, `'buy'` or `'sell'` |
| `oiDelta` | The trade's change in open interest: positive where it opened positions, negative where it closed them |
| `sameOrder` | Whether the same taker order filled the trade before it |
| `takerOrderId`, `tradeId` | Ids, on live trades; `null` in history |
| `liquidation` | Whether the taker was being liquidated |
| `taker`, `maker` | Wallets, where the source carries them; `null` in the terminal today |

## Sum the tape per bar

Add each trade to a [tally](/terminal/guides/state#tallies) in `onTrade`, and read it in the chart's `onBar`. This is volume delta, in USD:

```ts theme={"theme":"github-dark"}
indicator('Volume delta');

const chart = bars();
const tape = trades();
const delta = tally();
const deltaBars = plot.histogram('Delta $');

tape.onTrade((t) => delta.add(t.side === 'buy' ? t.notional : -t.notional));

chart.onBar(() => {
  if (!tape.available) return;
  deltaBars.set(delta.value, delta.value >= 0 ? color.up : color.down);
});
```

`minSize` and `minNotional` filter the stream, so `trades({ minNotional: 100_000 })` delivers only trades of \$100k or more.

## Opening and closing trades

0xArchive records each trade's change in open interest (`oiDelta`), in the market's coin. With the taker's side it says what the trade did:

| Taker trade | What happened |
| - | - |
| Buy, `oiDelta` above 0 | A new long |
| Buy, `oiDelta` below 0 | A short bought back |
| Sell, `oiDelta` above 0 | A new short |
| Sell, `oiDelta` below 0 | A long sold out |

An `oiDelta` of 0 means one side opened while the other closed. Hyperliquid and HIP-3 count both sides of open interest, Lighter longs only, as each venue's own open interest does. [Opening and closing flow](/terminal/examples/opening-closing-flow) and [Squeeze or new positions](/terminal/examples/squeeze-or-new-positions) are built on it.

## Taker orders

One market order fills against many resting orders, and each fill is a trade. `sameOrder` is true when the same taker order filled the trade before it, so a new order starts wherever it is false. That joins fills into orders across the whole history, where `takerOrderId` is `null`:

```ts theme={"theme":"github-dark"}
const order = state.live(0);
const orders = tallyBy(512);

tape.onTrade((t) => {
  if (!t.sameOrder) order.value += 1;
  orders.add(String(order.value), t.side === 'buy' ? t.notional : -t.notional);
});
```

[Large taker orders](/terminal/examples/large-takers) marks the bars where one came to \$1M or more.

## Order flow by bar, without events

Bars that close on trades (`t500`, `v1000000` and the rest) carry `buyVolume` and `sellVolume` on each bar. Time bars do not split volume, so sum `trades()` for them.

## Next step

Read liquidations and where they would happen next in [liquidations](/terminal/guides/liquidations).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.