> ## 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.

# Trades

> All Lighter DEX trades including voluntary trades, liquidations, and deleverages

The `lighter.dex.trades` table contains all DEX trades on Lighter including voluntary trades, liquidations, and deleverages. Use `trade_type` to filter by event type.

### Table Details

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

## Table Columns

### Trade Type

| Column Name  | Description                                                  |
| ------------ | ------------------------------------------------------------ |
| trade\_type  | Type of trade event: 'trade', 'liquidation', or 'deleverage' |
| market\_type | 'perpetuals' or 'spot'                                       |

### Market Information

| Column Name      | Description                         |
| ---------------- | ----------------------------------- |
| coin             | Market symbol (e.g., BTC, ETH/USDC) |
| token\_a\_symbol | Base token symbol                   |
| token\_b\_symbol | Quote token symbol                  |
| market\_id       | Lighter market ID                   |
| max\_leverage    | Maximum leverage for this market    |

### Trade Details

| Column Name       | Description                          |
| ----------------- | ------------------------------------ |
| amount            | Trade size in base asset units       |
| price             | Execution price                      |
| usd\_amount       | USD value of the trade               |
| is\_treasury      | True if treasury account is involved |
| is\_buyback       | True if this is a LIT buyback trade  |
| timestamp         | UTC timestamp of the trade           |
| transaction\_hash | On-chain transaction hash            |
| trade\_id         | Unique trade identifier              |
| unique\_id        | Alias of trade\_id                   |
| block\_height     | Block height of the trade            |

### Participants

| Column Name         | Description                                                 |
| ------------------- | ----------------------------------------------------------- |
| buyer               | Account ID of the buyer (bid side)                          |
| seller              | Account ID of the seller (ask side)                         |
| buyer\_l1\_address  | EVM wallet address of the buyer. NULL if no mapping exists  |
| seller\_l1\_address | EVM wallet address of the seller. NULL if no mapping exists |
| maker\_account\_id  | Account ID of the maker                                     |
| taker\_account\_id  | Account ID of the taker                                     |
| is\_maker\_ask      | True if the maker is on the ask (sell) side                 |

### Order Information

| Column Name        | Description                         |
| ------------------ | ----------------------------------- |
| buyer\_order\_id   | Order ID of the buyer's order       |
| seller\_order\_id  | Order ID of the seller's order      |
| buyer\_client\_id  | Client-assigned order ID for buyer  |
| seller\_client\_id | Client-assigned order ID for seller |

### Fees

| Column Name        | Description                   |
| ------------------ | ----------------------------- |
| fee\_token         | Token in which fees are paid  |
| buyer\_fee         | Fee paid by buyer in USD      |
| seller\_fee        | Fee paid by seller in USD     |
| maker\_fee\_rate   | Maker fee as decimal fraction |
| maker\_fee\_amount | Maker fee in USD              |
| taker\_fee\_rate   | Taker fee as decimal fraction |
| taker\_fee\_amount | Taker fee in USD              |

### Position Changes

| Column Name                     | Description                                 |
| ------------------------------- | ------------------------------------------- |
| buyer\_start\_position          | Buyer's position size before this trade     |
| seller\_start\_position         | Seller's position size before this trade    |
| buyer\_position\_sign\_changed  | Whether buyer's position flipped direction  |
| seller\_position\_sign\_changed | Whether seller's position flipped direction |

### Liquidation Fields

| Column Name               | Description                                                 |
| ------------------------- | ----------------------------------------------------------- |
| liquidated\_account\_id   | Account ID of the liquidated party. NULL for regular trades |
| counterparty\_account\_id | Account ID of the counterparty. NULL for regular trades     |
| liquidation\_fee\_rate    | Liquidation fee rate. NULL for regular trades               |
| liquidation\_fee\_amount  | Liquidation fee in USD. NULL for regular trades             |
| liquidated\_max\_leverage | Liquidated account's max leverage. NULL for regular trades  |

### Market Parameters

| Column Name                   | Description                          |
| ----------------------------- | ------------------------------------ |
| collateral\_symbol            | Collateral asset symbol (e.g., USDC) |
| maintenance\_margin\_fraction | Market maintenance margin fraction   |
| closeout\_margin\_fraction    | Market closeout margin fraction      |

## Sample Query

```sql theme={null}
SELECT
    timestamp,
    coin,
    trade_type,
    amount,
    price,
    usd_amount,
    buyer,
    seller
FROM lighter.dex.trades
WHERE timestamp >= CURRENT_DATE - 7
ORDER BY timestamp DESC
LIMIT 100
```
