> ## Documentation Index
> Fetch the complete documentation index at: https://sonar-cf3aeac7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Multi-events stream overview

> One WebSocket subscription for DEX trades across several chains, with server-side filters, per-pair cursors and resume.

The multi-events stream sends DEX trades (swaps) from several chains over one WebSocket subscription. You choose the chains and event kinds, and the server applies your filter before anything is sent. Each chain and event kind has its own cursor, so a client that disconnects can reconnect and pick up where it stopped.

Use it when you want every trade that matches a rule, for example every trade over \$100,000 on Ethereum and Base, or every trade sent by a list of wallets, without first knowing which tokens or pools those trades will touch.

## How it differs from the `/v1/ws` channels

The [WebSocket API](https://sonar-cf3aeac7.mintlify.site/websocket/overview.md) at `/v1/ws` and the multi-events stream use the same message protocol: the same `subscribe`, `unsubscribe` and `ping` ops, and the same `event`, `cursor`, `gap` and `error` messages. Their purpose is different.

| | `/v1/ws` channels | Multi-events stream |
| - | - | - |
| Endpoint | `wss://api.example.com/v1/ws` | `wss://api.example.com/streams/v1/ws` |
| Channels | `fast-trade`, `token-details`, `market-details`, `ohlcv` | `multi-events` only |
| What you subscribe to | One chain, and a token, pool or list of them | One or more chains, with a filter that can match any pool, token or wallet |
| Filtering | By the token or pool you name, plus `excludeNoise` on some channels | A filter expression over pool type, pool, token, wallet, side and USD size |
| Payload | Trade oriented to your token, with optional token, market or candle data | The raw trade (`swap`), or the raw trade plus token name, symbol, decimals and logo (`swap-enriched`) |
| Cursors | One per subscription | One per chain and event kind (a [pair](https://sonar-cf3aeac7.mintlify.site/streams/subscribing.md#pairs)) |

The `multi-events` channel is only served on the multi-events stream. Subscribing to `multi-events` on `/v1/ws` returns an `UNKNOWN_CHANNEL` error. The same happens if you subscribe to a `/v1/ws` channel such as `fast-trade` on the multi-events stream.

The stream doesn't add market stats, candles or token stats. If you need those, use the [`/v1/ws` channels](https://sonar-cf3aeac7.mintlify.site/websocket/overview) or the [REST API](https://sonar-cf3aeac7.mintlify.site/api-reference/overview.md).

## What is included

* **Trades only.** Only swaps classified as trades are streamed. Liquidity adds and removals, and swaps classified as MEV or as launchpad bonding, are not sent. Every payload has `"category": "TRADE"`.
* **Two event kinds.** `swap` is the trade as indexed and priced. `swap-enriched` is the same trade with `baseTokenData` and `quoteTokenData` added. See [Event payloads](https://sonar-cf3aeac7.mintlify.site/streams/event-payloads.md).
* **Once per kind.** If you request both kinds, each matching trade is sent once as `swap` and once as `swap-enriched`.

## Chains

Chains are identified as `evm:<chainId>` strings. Bare numbers such as `1` and names such as `ethereum` are rejected. See [Chains and identifiers](https://sonar-cf3aeac7.mintlify.site/concepts/chains-and-identifiers.md).

| Chain | Identifier |
| - | - |
| Ethereum | `evm:1` |
| Base | `evm:8453` |
| BNB Smart Chain | `evm:56` |
| Robinhood | `evm:4663` |

> [!WARNING]
>
> The server accepts any `evm:<n>` value and doesn't check that the chain is indexed. A subscription to a chain that has no data succeeds and never delivers an event.

## Connect

```text theme={null}
wss://api.example.com/streams/v1/ws
```

* There is no authentication. You don't need an API key or token.
* Messages are JSON text frames in both directions.

As soon as the socket opens, the server sends a `welcome` message:

```json theme={null}
{ "type": "welcome", "connectionId": "8b0f3c2e-5a41-4f7d-9d6e-2c1b7a9e4f10", "heartbeatMs": 30000 }
```

| Field | Meaning |
| - | - |
| `connectionId` | Random UUID for this connection. Useful in logs. |
| `heartbeatMs` | Interval of the server's WebSocket ping frames. Most clients answer them automatically. See [Limits](https://sonar-cf3aeac7.mintlify.site/streams/limits-and-cost.md#heartbeat). |

If the server is restarting or at capacity, the upgrade is refused with HTTP `503 Service Unavailable`. Retry with backoff.

## Quick example: large WETH buys on Ethereum

This subscription sends every Ethereum trade where WETH was bought for \$100,000 or more.

```json theme={null}
{
  "op": "subscribe",
  "id": "weth-whales",
  "channel": "multi-events",
  "params": {
    "chains": ["evm:1"],
    "events": ["swap"],
    "filters": {
      "and": [
        { "eq": ["tokenAddress", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"] },
        { "eq": ["type", "buy"] },
        { "gte": ["tokenAmountUsd", 100000] }
      ]
    }
  }
}
```

```js JavaScript theme={null}
// Node.js 22+ and browsers have a global WebSocket.
const ws = new WebSocket("wss://api.example.com/streams/v1/ws");

ws.onopen = () => {
  ws.send(JSON.stringify({
    op: "subscribe",
    id: "weth-whales",
    channel: "multi-events",
    params: {
      chains: ["evm:1"],
      events: ["swap"],
      filters: {
        and: [
          { eq: ["tokenAddress", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"] },
          { eq: ["type", "buy"] },
          { gte: ["tokenAmountUsd", 100000] },
        ],
      },
    },
  }));
};

ws.onmessage = ({ data }) => {
  const msg = JSON.parse(data);
  if (msg.type === "event") {
    const s = msg.data;
    console.log(`${s.hash} $${Math.round(s.amountUSD)} in pool ${s.pool}`);
  } else if (msg.type === "error") {
    console.error(msg.code, msg.message, msg.details);
  }
};
```

```python Python theme={null}
# pip install websockets
import asyncio, json
import websockets

URL = "wss://api.example.com/streams/v1/ws"
WETH = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"

async def main():
    async with websockets.connect(URL) as ws:
        await ws.send(json.dumps({
            "op": "subscribe",
            "id": "weth-whales",
            "channel": "multi-events",
            "params": {
                "chains": ["evm:1"],
                "events": ["swap"],
                "filters": {"and": [
                    {"eq": ["tokenAddress", WETH]},
                    {"eq": ["type", "buy"]},
                    {"gte": ["tokenAmountUsd", 100000]},
                ]},
            },
        }))
        async for raw in ws:
            msg = json.loads(raw)
            if msg["type"] == "event":
                s = msg["data"]
                print(s["hash"], round(s["amountUSD"]), s["pool"])
            elif msg["type"] == "error":
                print("error", msg["code"], msg["message"], msg.get("details"))

asyncio.run(main())
```

```bash wscat theme={null}
npx wscat -c wss://api.example.com/streams/v1/ws
# then paste the subscribe message above on one line
```

A session looks like this (`→` is sent by you, `←` by the server; values are illustrative):

```text theme={null}
← {"type":"welcome","connectionId":"8b0f3c2e-5a41-4f7d-9d6e-2c1b7a9e4f10","heartbeatMs":30000}
→ {"op":"subscribe","id":"weth-whales","channel":"multi-events","params":{...}}
← {"type":"subscribed","id":"weth-whales","channel":"multi-events","cursor":"26745119-0"}
← {"type":"event","id":"weth-whales","channel":"multi-events","cursor":"26745120-0:3","data":{"event":"swap","chainId":"evm:1","blockNumber":26745120,...,"amountUSD":250000}}
← {"type":"cursor","id":"weth-whales","cursor":"26745122-0"}
```

The `cursor` values let you resume after a disconnect. See [Cursors and resuming](https://sonar-cf3aeac7.mintlify.site/streams/cursors-and-resume.md).

## How data flows

Indexers decode swaps from each chain, price them in USD, and publish each block's trades in block order to a per-chain stream. The multi-events service reads those streams and sends every subscriber the trades its filter matches. Blocks are released strictly in order. If a block is stuck for more than about 15 seconds, the stream skips it and tells subscribers with a [`gap`](https://sonar-cf3aeac7.mintlify.site/streams/cursors-and-resume#gaps) message. See [How data flows](https://sonar-cf3aeac7.mintlify.site/concepts/how-data-flows.md) for the wider picture.

## Next steps

> [card] [Subscribing](https://sonar-cf3aeac7.mintlify.site/streams/subscribing.md)
>
> Params, pairs, the `subscribed` reply and sampling.

> [card] [Event payloads](https://sonar-cf3aeac7.mintlify.site/streams/event-payloads.md)
>
> Every field of `swap` and `swap-enriched`, and how to derive buy or sell.

> [card] [Filters](https://sonar-cf3aeac7.mintlify.site/streams/filters.md)
>
> The filter grammar, limits and a cookbook.

> [card] [Limits and subscription cost](https://sonar-cf3aeac7.mintlify.site/streams/limits-and-cost.md)
>
> How filters are priced and what closes a connection.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.