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

# Order Books

> Flattened order book updates with bid/ask levels

The `lighter.dex.order_books` table provides flattened order book updates. One row per market/update/side/level.

### Table Details

| Property          | Value                               |
| ----------------- | ----------------------------------- |
| Clustering Key(s) | `to_date("timestamp")` (base table) |

## Table Columns

### Market Information

| Column Name        | Description                                                |
| ------------------ | ---------------------------------------------------------- |
| market\_id         | Lighter market ID                                          |
| symbol             | Market symbol (e.g., BTC, ETH/USDC)                        |
| market\_type       | 'perpetuals' or 'spot'                                     |
| base\_symbol       | Base asset symbol                                          |
| quote\_symbol      | Quote asset symbol                                         |
| collateral\_symbol | Collateral asset symbol for perpetuals. NULL for spots     |
| base\_l1\_address  | L1 contract address of the base asset. NULL for perpetuals |

### Order Book Data

| Column Name | Description                                |
| ----------- | ------------------------------------------ |
| timestamp   | UTC timestamp of the order book update     |
| side        | 'ask' or 'bid'                             |
| level       | 0-based index within the ask or bid array  |
| price       | Price at this level in quote asset units   |
| size        | Size at this level in base asset units     |
| usd\_amount | Dollar value at this level (price \* size) |

### Sequence Information

| Column Name  | Description                               |
| ------------ | ----------------------------------------- |
| nonce        | Global sequence number at update time     |
| begin\_nonce | Sequence number at the start of the batch |
| book\_offset | Per-market incrementing version counter   |

## Sample Query

The underlying data is clustered by `to_date("timestamp")`. Filter by date for efficient queries. Example using the raw table (same clustering applies when querying the view):

```sql theme={null}
SELECT
    market_id,
    timestamp,
    nonce,
    asks,
    bids
FROM lighter.raw.order_books
WHERE timestamp >= CURRENT_DATE
ORDER BY timestamp DESC
LIMIT 100
```

To query the flattened view `lighter.dex.order_books` (symbol, side, level, price, size, usd\_amount), use the same date filter: `WHERE timestamp >= CURRENT_DATE` (and optionally `AND symbol = 'BTC'`).
