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

> DEX trades including voluntary trades, liquidations, and deleverages.

The `lighter_robinhood.dex.trades` table contains dex trades including voluntary trades, liquidations, and deleverages.

## Table Columns

**Unique key:** `trade_id`

| Column Name                            | Data Type          | Description                                                                       |
| -------------------------------------- | ------------------ | --------------------------------------------------------------------------------- |
| `trade_type`                           | `VARCHAR`          | Type of trade event: 'trade', 'liquidation', or 'deleverage'.                     |
| `market_type`                          | `VARCHAR`          | 'perpetuals' or 'spot'.                                                           |
| `coin`                                 | `VARCHAR`          | Market symbol (e.g., BTC, ETH/USDG).                                              |
| `token_a_symbol`                       | `VARCHAR`          | Base token symbol.                                                                |
| `token_b_symbol`                       | `VARCHAR`          | Quote token symbol.                                                               |
| `amount`                               | `NUMBER(22,10)`    | Trade size in base asset units.                                                   |
| `price`                                | `NUMBER(22,10)`    | Execution price.                                                                  |
| `usd_amount`                           | `NUMBER(22,10)`    | USD value of the trade.                                                           |
| `is_treasury`                          | `BOOLEAN`          | True if treasury account is involved.                                             |
| `is_buyback`                           | `BOOLEAN`          | Indicates LIT buyback activity. No such activity is reported for this deployment. |
| `buyer`                                | `VARCHAR`          | Account ID of the buyer (bid side).                                               |
| `seller`                               | `VARCHAR`          | Account ID of the seller (ask side).                                              |
| `buyer_l1_address`                     | `VARCHAR`          | EVM wallet address of the buyer. NULL if no mapping exists.                       |
| `seller_l1_address`                    | `VARCHAR`          | EVM wallet address of the seller. NULL if no mapping exists.                      |
| `maker_account_id`                     | `VARCHAR`          | Account ID of the maker.                                                          |
| `taker_account_id`                     | `VARCHAR`          | Account ID of the taker.                                                          |
| `liquidated_account_id`                | `VARCHAR`          | Account ID of the liquidated party. NULL for regular trades.                      |
| `counterparty_account_id`              | `VARCHAR`          | Account ID of the counterparty. NULL for regular trades.                          |
| `timestamp`                            | `TIMESTAMP_NTZ(9)` | UTC timestamp of the trade.                                                       |
| `transaction_hash`                     | `VARCHAR`          | On-chain transaction hash.                                                        |
| `trade_id`                             | `VARCHAR`          | Unique trade identifier.                                                          |
| `unique_id`                            | `VARCHAR`          | Unique identifier for the trade.                                                  |
| `is_maker_ask`                         | `BOOLEAN`          | True if the maker is on the ask (sell) side.                                      |
| `block_height`                         | `NUMBER(38,0)`     | Block height of the trade.                                                        |
| `buyer_order_id`                       | `VARCHAR`          | Order ID of the buyer's order.                                                    |
| `seller_order_id`                      | `VARCHAR`          | Order ID of the seller's order.                                                   |
| `buyer_client_id`                      | `VARCHAR`          | Client-assigned order ID for buyer.                                               |
| `seller_client_id`                     | `VARCHAR`          | Client-assigned order ID for seller.                                              |
| `fee_token`                            | `VARCHAR`          | Token in which fees are paid.                                                     |
| `buyer_fee`                            | `NUMBER(22,10)`    | Fee paid by buyer in USD.                                                         |
| `seller_fee`                           | `NUMBER(22,10)`    | Fee paid by seller in USD.                                                        |
| `maker_fee_rate`                       | `NUMBER(22,10)`    | Maker fee rate as a decimal fraction.                                             |
| `maker_fee_amount`                     | `NUMBER(22,10)`    | Maker fee in USD.                                                                 |
| `taker_fee_rate`                       | `NUMBER(22,10)`    | Taker fee rate as a decimal fraction.                                             |
| `taker_fee_amount`                     | `NUMBER(22,10)`    | Taker fee in USD.                                                                 |
| `liquidation_fee_rate`                 | `NUMBER(22,10)`    | Liquidation fee rate as a decimal fraction.                                       |
| `liquidation_fee_amount`               | `NUMBER(22,10)`    | Liquidation fee in USD. NULL for regular trades.                                  |
| `buyer_start_position`                 | `NUMBER(22,10)`    | Buyer's position size before this trade.                                          |
| `seller_start_position`                | `NUMBER(22,10)`    | Seller's position size before this trade.                                         |
| `taker_position_size_before`           | `NUMBER(22,10)`    | Taker's position size before this trade.                                          |
| `taker_entry_quote_before`             | `NUMBER(22,10)`    | Taker's entry quote before this trade.                                            |
| `taker_initial_margin_fraction_before` | `NUMBER(22,10)`    | Taker's initial margin fraction before this trade.                                |
| `maker_position_size_before`           | `NUMBER(22,10)`    | Maker's position size before this trade.                                          |
| `maker_entry_quote_before`             | `NUMBER(22,10)`    | Maker's entry quote before this trade.                                            |
| `maker_initial_margin_fraction_before` | `NUMBER(22,10)`    | Maker's initial margin fraction before this trade.                                |
| `buyer_position_sign_changed`          | `BOOLEAN`          | Whether buyer's position flipped direction.                                       |
| `seller_position_sign_changed`         | `BOOLEAN`          | Whether seller's position flipped direction.                                      |
| `taker_position_sign_changed`          | `BOOLEAN`          | Whether the taker's position sign changed.                                        |
| `maker_position_sign_changed`          | `BOOLEAN`          | Whether the maker's position sign changed.                                        |
| `market_id`                            | `NUMBER(38,0)`     | Lighter market ID.                                                                |
| `base_l1_address`                      | `VARCHAR`          | L1 contract address of the base asset, when applicable.                           |
| `collateral_asset_id`                  | `NUMBER(38,0)`     | Collateral asset ID for perpetuals.                                               |
| `collateral_symbol`                    | `VARCHAR`          | Collateral asset symbol (for example, USDG).                                      |
| `max_leverage`                         | `NUMBER(12,6)`     | Maximum leverage for this market.                                                 |
| `liquidated_max_leverage`              | `NUMBER(12,6)`     | Liquidated account's max leverage. NULL for regular trades.                       |
| `maintenance_margin_fraction`          | `NUMBER(38,0)`     | Market maintenance margin fraction.                                               |
| `closeout_margin_fraction`             | `NUMBER(38,0)`     | Market closeout margin fraction.                                                  |
| `transaction_time`                     | `VARCHAR`          | Unix transaction timestamp in microseconds, represented as text.                  |
| `transaction_time_ts`                  | `TIMESTAMP_NTZ(9)` | UTC transaction timestamp.                                                        |
| `_created_at`                          | `TIMESTAMP_NTZ(9)` | Timestamp when the row was first recorded.                                        |
| `_updated_at`                          | `TIMESTAMP_NTZ(9)` | Timestamp when the row was last updated.                                          |

### Sample Query

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