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

# Trades

> The trade table: every curve buy and sell, plus Uniswap v4 swaps on chains where pool swaps are indexed, with execution price and fee.

`trade` records one row per `Buy` or `Sell` event on a bonding curve and, on chains that index the `PoolManager`, one row per `Swap` in a graduated launch's pool. It is the source of the trade list on the token page and of `launch.volumeQuote` and `tradeCount`.

## Fields

| Field         | Type    | Unit                  | Meaning                                                                                      |
| ------------- | ------- | --------------------- | -------------------------------------------------------------------------------------------- |
| `id`          | text    |                       | `txHash-logIndex`. Primary key.                                                              |
| `launch`      | hex     | address               | Launch token address.                                                                        |
| `type`        | enum    |                       | `buy` or `sell` on the curve, `swap` on the Uniswap v4 pool.                                 |
| `isBuy`       | boolean |                       | True when the trader received launch tokens (a curve buy, or a swap out of the quote asset). |
| `trader`      | hex     | address               | Transaction sender. The contract-level caller is normally the Router or the Factory.         |
| `recipient`   | hex     | address               | Who received the tokens (buy) or the quote (sell). `null` for swaps.                         |
| `tokenAmount` | bigint  | 18 decimals           | Tokens bought or sold.                                                                       |
| `quoteAmount` | bigint  | quote units           | Buys: gross quote paid, fee included. Sells: net quote received. Swaps: quote moved.         |
| `fee`         | bigint  | quote units           | Trade fee. For swaps an estimate: the pool fee in pips on the input amount.                  |
| `priceQuote`  | bigint  | quote per token, 1e18 | Execution price, `quoteAmount / tokenAmount`.                                                |
| `priceUsd`    | bigint  | USD per token, 1e18   | `null` when no rate was indexed for the launch's currency at that time.                      |
| `timestamp`   | bigint  | unix seconds          |                                                                                              |
| `blockNumber` | bigint  |                       |                                                                                              |
| `txHash`      | hex     |                       |                                                                                              |
| `logIndex`    | int     |                       |                                                                                              |

Indexes: `(launch, timestamp)`, `trader`, `timestamp`. Filter on `launch` or `trader` and order by `timestamp` for the cheap paths.

<Note>
  The curve emits `Buy` and `Sell` with the post-trade `tokensSold` and `realQuote`; the indexer uses those to update the launch row and the candles with the spot price after the trade, while `priceQuote` here is the average price the trade actually got.
</Note>

## Examples

Latest trades of a launch, cursor paginated:

```graphql theme={"system"}
query Trades($token: String!, $after: String) {
  trades(where: { launch: $token }, orderBy: "timestamp", orderDirection: "desc", limit: 50, after: $after) {
    items {
      id type isBuy trader recipient tokenAmount quoteAmount fee priceQuote priceUsd timestamp blockNumber txHash logIndex
    }
    pageInfo { hasNextPage endCursor }
  }
}
```

Only curve buys, or only pool swaps:

```graphql theme={"system"}
{
  buys: trades(where: { launch: "0x...", type: "buy" }, orderBy: "timestamp", orderDirection: "desc", limit: 20) {
    items { trader quoteAmount tokenAmount priceQuote timestamp }
  }
  swaps: trades(where: { launch: "0x...", type: "swap" }, orderBy: "timestamp", orderDirection: "desc", limit: 20) {
    items { isBuy quoteAmount tokenAmount priceQuote timestamp txHash }
  }
}
```

One wallet's trading history across every launch, with the launch it belongs to:

```graphql theme={"system"}
query Wallet($trader: String!) {
  trades(where: { trader: $trader }, orderBy: "timestamp", orderDirection: "desc", limit: 100) {
    items {
      type isBuy tokenAmount quoteAmount priceQuote timestamp txHash
      launchInfo { symbol name currency quoteDecimals }
    }
  }
}
```

Trades in a time window (for a 24-hour volume figure):

```graphql theme={"system"}
query Recent($token: String!, $since: BigInt!) {
  trades(where: { launch: $token, timestamp_gte: $since }, orderBy: "timestamp", orderDirection: "asc", limit: 1000) {
    items { quoteAmount isBuy timestamp }
  }
}
```

Large trades only (`quoteAmount` is a bigint, so the threshold is a string in quote units; this is 1,000 units of the launch currency):

```graphql theme={"system"}
{
  trades(where: { launch: "0x...", quoteAmount_gte: "1000000000000000000000" }, orderBy: "quoteAmount", orderDirection: "desc", limit: 10) {
    items { trader type quoteAmount tokenAmount txHash }
  }
}
```

A single trade by id:

```graphql theme={"system"}
{ trade(id: "0x<txHash>-<logIndex>") { type trader quoteAmount tokenAmount priceQuote } }
```

With `curl`:

```bash theme={"system"}
curl -s https://api.windrose.market/graphql \
  -H 'content-type: application/json' \
  -d '{"query":"query($t:String!){ trades(where:{launch:$t}, orderBy:\"timestamp\", orderDirection:\"desc\", limit:5){ items { type trader quoteAmount tokenAmount priceQuote timestamp txHash } } }","variables":{"t":"0x..."}}'
```

## Units that matter here

* `quoteAmount`, `fee` and the `_gte` thresholds are quote units: the launch's quote asset scaled to 18 decimals. Divide by `1e18` for a human amount of the currency, whatever `quoteDecimals` is.
* `priceQuote / 1e18` is the price per whole token in the launch currency; `priceUsd / 1e18` is the same in USD at the rate current when the trade was indexed.
* Sum `quoteAmount` over a window for volume; the buy rows include the fee and the sell rows exclude it, matching what `launch.volumeQuote` accumulates.
* On Robinhood Chain there are no `swap` rows, because the shared official `PoolManager` is not indexed there. The testnets do record swaps. See [how the data is produced](/api#how-the-data-is-produced).
