# DEX trades API

> One trade feed, newest first, for a token, a pool, a wallet or a transaction, with the same row everywhere.

## Read a token's trades

[`GET /trades`](https://app.aurelia.build/docs/trades) takes `chain` and exactly one of `token`, `pool`, `wallet` or `tx`. A token's feed covers all of its pools.

The newest 50 trades of a token:

```bash
curl -s -H 'Authorization: Bearer <key>' 'https://app.aurelia.build/api/trades?chain=solana&token=So11111111111111111111111111111111111111112&limit=50'
```

## Filter them

| You want | Add |
|---|---|
| Large buys | `side=buy&minUsd=10000` |
| Small sells | `side=sell&maxUsd=100` |
| One wallet's trades in this token | `trader=<wallet>` |
| Trades by wallets with a [label](https://app.aurelia.build/docs/labels) | `label=sniper` |

Buys of $1,000 or more:

```bash
curl -s -H 'Authorization: Bearer <key>' 'https://app.aurelia.build/api/trades?chain=solana&token=So11111111111111111111111111111111111111112&side=buy&minUsd=1000&limit=50'
```

A trade without a USD price never matches `minUsd`.

## Page through history

`limit` is 1 to 200. Pass the previous answer's `next` as `cursor`, as it came. The answer's `indexedSince` says how far back the feed goes.

Walk a feed:

```javascript
let cursor = null;
do {
  const url = new URL("https://app.aurelia.build/api/trades");
  url.search = new URLSearchParams({ chain: "solana", token: "So11111111111111111111111111111111111111112", limit: "200", ...(cursor && { cursor }) });
  const res = await fetch(url, { headers: { Authorization: "Bearer <key>" } });
  const { trades, next } = await res.json();
  for (const t of trades) console.log(t.time, t.side, t.amount, t.priceUsd);
  cursor = next;
} while (cursor);
```

## See every leg of a route

With `tx`, you get every swap of one transaction from the last 7 days: each leg of a router's path.

## Stream new trades

Subscribe to the [trades channel](https://app.aurelia.build/docs/live-trades) with one of `token`, `pool` or `wallet`. Each message carries the rows of one indexed batch, in the same shape. Nothing is replayed, so on `subscribed` and on `resubscribed`, read the recent trades over REST and merge them, keyed by `tx`, `pool` and `eventIndex`.

Subscribe:

```json
{"op":"subscribe","id":"t","channel":"trades","chain":"solana","token":"So11111111111111111111111111111111111111112"}
```

## Related

- [Trades reference](https://app.aurelia.build/docs/trades): every field of a row.
- [Token traders](https://app.aurelia.build/docs/token-traders): a token's wallets by PnL or volume.
- [Wallet PnL API](https://app.aurelia.build/guides/wallet-pnl-api).
