# Events

> Event types served by /query/v1/events, their columns, flags and billing.

Source: https://getmarkethistory.com/docs/events

<!-- GENERATED by tools/gen_formats_docs.py from formats/events.yaml. Do not edit by hand. -->

Events are rows a venue publishes one at a time: liquidations, fills, open interest as it changes, a perpetual's context. Each type below is one track per ticker, read in time order with

```
GET /query/v1/events/{asset}/{region}/{ticker}?type=<type>&start=…&end=…&limit=…
```

Pages follow `cursor` (the `X-Next-Cursor` header) on the key `(ts, seq)`. A type is served once its feed is live; until then the route answers `404` and lists the types served (now: `market_structure`, `market_structure_exchange`).

## Reading the rows

- **`ts`** orders a type's rows. Its basis is the type's: `venue` (the venue's event time), `receive` (the time the row was received; the venue's own time, when it sends one, is `venue_ts`) or `block` (the time of the chain block holding the event).
- **`flags`**: bit 0 `GAP`, bit 1 `RESYNC`, bit 2 `SNAPSHOT`, bit 3 `INFERRED`. A `GAP` row says the feed was not observed from its `ts` to its `gap_end` (or to the next row when `gap_end` is null); its values are null. A `RESYNC` row is the first after listening (re)started; `SNAPSHOT` marks a value taken from a full-state message.
- **State** types (`semantics: state`) are written when a value changes: the value holds until the next row, unless a `GAP` row intervenes. `res_ms` is each row's resolution: 0 when every change is recorded, else the interval of the source that produced it, so a change may have happened up to `res_ms` before the row.
- **Occurrence** types have one row per event; a `RESYNC` row there is a marker with null values.
- Enumerations are served as their numbers; the labels are listed below.

## Billing

One billable row is one bar. `GAP` rows and an occurrence type's `RESYNC` markers are free (they still count toward `limit`); `RESYNC` rows of a state type carry a value and are billed. `X-Row-Count` is the page's billable rows.

## `liquidations`

Forced closes of positions, one row per liquidation order.

Status: **not live yet**. Semantics: occurrence; `ts` basis: venue.

| column | type | unit | null | values |
|---|---|---|---|---|
| `ts` | timestamp (ns, UTC) | ns | no |  |
| `seq` | uint64 |  | no |  |
| `side` | uint8 |  | no | 65 = A, 66 = B |
| `price` | float | quote | no |  |
| `size` | float | base | no |  |
| `order_id` | uint64 |  | yes |  |
| `kind` | uint8 |  | no | 0 = forced_order, 1 = last_of_interval |
| `recv_ts` | timestamp (ns, UTC) | ns | yes |  |
| `recorder` | uint32 |  | yes |  |
| `flags` | uint8 |  | no | 1 = GAP, 2 = RESYNC, 4 = SNAPSHOT, 8 = INFERRED |
| `gap_end` | timestamp (ns, UTC) | ns | yes |  |

## `dex_fills`

Fills of an on-chain exchange, one row per fill, timed by its block.

Status: **not live yet**. Semantics: occurrence; `ts` basis: block.

| column | type | unit | null | values |
|---|---|---|---|---|
| `ts` | timestamp (ns, UTC) | ns | no |  |
| `seq` | uint64 |  | no |  |
| `side` | uint8 |  | no | 65 = A, 66 = B |
| `price` | float | quote | no |  |
| `size` | float | base | no |  |
| `dir` | uint8 |  | no | 0 = Open Long, 1 = Open Short, 2 = Close Long, 3 = Close Short |
| `crossed` | bool |  | no |  |
| `fee` | float |  | no |  |
| `fee_token` | uint8 |  | no | 0 = USDC |
| `builder_fee` | float |  | yes |  |
| `closed_pnl` | float | quote | no |  |
| `start_position` | float | base | no |  |
| `oid` | uint64 |  | no |  |
| `tid` | uint64 |  | no |  |
| `twap_id` | uint64 |  | yes |  |
| `liquidation` | bool |  | yes |  |
| `flags` | uint8 |  | no | 1 = GAP, 2 = RESYNC, 4 = SNAPSHOT, 8 = INFERRED |
| `gap_end` | timestamp (ns, UTC) | ns | yes |  |

## `open_interest_changes`

Open interest as it changes, recorded live; a coarse source's rows carry res_ms.

Status: **not live yet**. Semantics: state; `ts` basis: receive.

| column | type | unit | null | values |
|---|---|---|---|---|
| `ts` | timestamp (ns, UTC) | ns | no |  |
| `seq` | uint64 |  | no |  |
| `venue_ts` | timestamp (ns, UTC) | ns | yes |  |
| `oi` | float | contracts | no |  |
| `recorder` | uint32 |  | no |  |
| `flags` | uint8 |  | no | 1 = GAP, 2 = RESYNC, 4 = SNAPSHOT, 8 = INFERRED |
| `gap_end` | timestamp (ns, UTC) | ns | yes |  |
| `res_ms` | uint32 | ms | no | the row's resolution, 0 = every change |

## `perp_context`

A perpetual's funding, premium, oracle, mark and impact prices, volume and open interest, polled once a minute.

Status: **not live yet**. Semantics: state; `ts` basis: receive; source resolution 60,000 ms.

| column | type | unit | null | values |
|---|---|---|---|---|
| `ts` | timestamp (ns, UTC) | ns | no |  |
| `seq` | uint64 |  | no |  |
| `funding` | float |  | no |  |
| `premium` | float |  | no |  |
| `oracle_px` | float | quote | no |  |
| `mark_px` | float | quote | no |  |
| `mid_px` | float | quote | yes |  |
| `impact_bid_px` | float | quote | yes |  |
| `impact_ask_px` | float | quote | yes |  |
| `day_ntl_vlm` | float | quote | no |  |
| `prev_day_px` | float | quote | no |  |
| `open_interest` | float | base | no |  |
| `recorder` | uint32 |  | no |  |
| `flags` | uint8 |  | no | 1 = GAP, 2 = RESYNC, 4 = SNAPSHOT, 8 = INFERRED |
| `gap_end` | timestamp (ns, UTC) | ns | yes |  |
| `res_ms` | uint32 | ms | no | the row's resolution, 0 = every change |

## `market_structure`

The SEC's daily market structure metrics of one US stock or ETF across the exchanges it measures (cancels, trades, odd lots, hidden trades, order and trade volume, size and activity deciles).

Status: **served**. Semantics: occurrence; `ts` basis: venue.

| column | type | unit | null | values |
|---|---|---|---|---|
| `ts` | timestamp (ns, UTC) | ns | no |  |
| `seq` | uint64 |  | no |  |
| `security` | uint8 |  | no | 0 = Stock, 1 = ETF |
| `mcap_rank` | uint8 |  | yes |  |
| `turn_rank` | uint8 |  | yes |  |
| `volatility_rank` | uint8 |  | yes |  |
| `price_rank` | uint8 |  | yes |  |
| `cancels` | int64 | count | yes |  |
| `trades` | int64 | count | yes |  |
| `lit_trades` | int64 | count | yes |  |
| `odd_lots` | int64 | count | yes |  |
| `hidden` | int64 | count | yes |  |
| `trades_for_hidden` | int64 | count | yes |  |
| `trades_for_odd_lots` | int64 | count | yes |  |
| `order_vol` | int64 | shares | yes |  |
| `trade_vol` | int64 | shares | yes |  |
| `lit_vol` | int64 | shares | yes |  |
| `odd_lot_vol` | int64 | shares | yes |  |
| `hidden_vol` | int64 | shares | yes |  |
| `trade_vol_for_hidden` | int64 | shares | yes |  |
| `trade_vol_for_odd_lots` | int64 | shares | yes |  |
| `flags` | uint8 |  | no | 1 = GAP, 2 = RESYNC, 4 = SNAPSHOT, 8 = INFERRED |
| `gap_end` | timestamp (ns, UTC) | ns | yes |  |

## `market_structure_exchange`

The same metrics per exchange, one row per security, exchange and trading day (seq orders a day's exchanges by code).

Status: **served**. Semantics: occurrence; `ts` basis: venue.

| column | type | unit | null | values |
|---|---|---|---|---|
| `ts` | timestamp (ns, UTC) | ns | no |  |
| `seq` | uint64 |  | no |  |
| `security` | uint8 |  | no | 0 = Stock, 1 = ETF |
| `exchange` | uint8 |  | no | 0 = Amex, 1 = Arca, 2 = Bats-Y, 3 = Bats-Z, 4 = Boston, 5 = CHX, 6 = Edge-A, 7 = Edge-X, 8 = Nasdaq, 9 = NSX, 10 = NYSE, 11 = Phlx, 12 = IEX, 13 = MEMX, 14 = MIAX, 255 = none |
| `mcap_rank` | uint8 |  | yes |  |
| `turn_rank` | uint8 |  | yes |  |
| `volatility_rank` | uint8 |  | yes |  |
| `price_rank` | uint8 |  | yes |  |
| `cancels` | int64 | count | yes |  |
| `trades` | int64 | count | yes |  |
| `lit_trades` | int64 | count | yes |  |
| `odd_lots` | int64 | count | yes |  |
| `hidden` | int64 | count | yes |  |
| `trades_for_hidden` | int64 | count | yes |  |
| `trades_for_odd_lots` | int64 | count | yes |  |
| `order_vol` | int64 | shares | yes |  |
| `trade_vol` | int64 | shares | yes |  |
| `lit_vol` | int64 | shares | yes |  |
| `odd_lot_vol` | int64 | shares | yes |  |
| `hidden_vol` | int64 | shares | yes |  |
| `trade_vol_for_hidden` | int64 | shares | yes |  |
| `trade_vol_for_odd_lots` | int64 | shares | yes |  |
| `flags` | uint8 |  | no | 1 = GAP, 2 = RESYNC, 4 = SNAPSHOT, 8 = INFERRED |
| `gap_end` | timestamp (ns, UTC) | ns | yes |  |
