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

# Pulse live stream

> Subscribe to Pulse views over WebSocket. Get a ranked snapshot, then real-time token-added, token-updated and token-removed messages.

The Pulse stream keeps a board of [views](https://sonar-cf3aeac7.mintlify.site/pulse/views-and-models.md) up to date in real time. You subscribe with the same request body you would send to [`POST /pulse/views`](https://sonar-cf3aeac7.mintlify.site/pulse/rest-views). The server answers with a snapshot of every view, then sends a message whenever a token enters a view, changes, or leaves it.

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

> [!NOTE]
>
> This endpoint is separate from the [channel WebSocket](https://sonar-cf3aeac7.mintlify.site/websocket/overview.md) at `/v1/ws`. It has its own small protocol, described on this page. The channel protocol's messages, limits, cursors and `reconnect` message do not apply here.

* There is no authentication. Query strings on the URL are ignored.
* Every client message is a JSON **text** frame with an `op` field.
* Every server message is a JSON object with a `type` field. Snapshots can optionally be gzip-compressed binary frames (see [Compression](#compression)).

## Quick test with wscat

```bash theme={null}
npx wscat -c wss://api.example.com/v1/ws/pulse
> {"op":"subscribe","id":"board","params":{"chainId":["evm:8453"]}}
< {"type":"snapshot","id":"board","reason":"initial","data":{"new":{"data":[...]},"bonding":{"data":[...]},"bonded":{"data":[...]}}}
< {"type":"token-added","id":"board","view":"new","token":{...}}
```

## Client operations

| `op` | Fields | Effect | Reply |
| - | - | - | - |
| `subscribe` | `id` (optional), `params` | Create or replace a subscription | `snapshot` with `reason: "initial"` |
| `pause` | `id` (optional), `views` | Stop events for these views | none |
| `resume` | `id` (optional), `views` | Restart events for these views | `snapshot` with `reason: "resync"` for the resumed views |
| `unsubscribe` | `id` (optional), `view` (optional) | Remove a subscription, a view, or everything | none |
| `ping` | none | Application-level keepalive | `pong` |

### subscribe

```json theme={null}
{
  "op": "subscribe",
  "id": "board",
  "params": {
    "chainId": ["evm:8453"],
    "views": [
      { "name": "new", "model": "new" },
      { "name": "bonding", "model": "bonding" },
      { "name": "hot", "sortBy": "volume_5min", "limit": 20, "filters": { "liquidity": { "gte": 20000 } } }
    ]
  }
}
```

| Field | Type | Description |
| - | - | - |
| `id` | string, 1 to 128 characters | Your name for the subscription. Every message about it carries this `id`. If omitted, the server generates a UUID and uses it in every message for this subscription. |
| `params` | object | The same request object as [`POST /pulse/views`](https://sonar-cf3aeac7.mintlify.site/pulse/views-and-models#request-object): `views`, `chainId`, `poolTypes`, plus `compressed`. |
| `params.compressed` | boolean | Send this subscription's snapshots as gzip-compressed binary frames. Default `false`. |

Differences from the REST endpoint:

* The default `limit` per view is **50** (REST uses 30). The maximum is still 100.
* `offset` is not available. Any view with `offset` above 0 is rejected with `views.<i>.offset: not available on the stream`.
* Omit `views` to get the default `new`, `bonding` and `bonded` views.

There is no separate acknowledgement: a successful subscribe is answered with an initial `snapshot`. Sending `subscribe` again with the **same `id`** on the same connection replaces that subscription; its old views are dropped and you get a new initial snapshot. Use different ids to hold several subscriptions on one connection.

### pause and resume

```json theme={null}
{ "op": "pause", "id": "board", "views": ["bonded"] }
```

```json theme={null}
{ "op": "resume", "id": "board", "views": ["bonded"] }
```

* `views` is required and lists at least one view name.
* Without `id`, the operation applies to views with those names in **every** subscription on the connection.
* A paused view gets no `token-*` messages and no periodic resyncs. Use it for views that are off screen.
* `resume` immediately sends a `snapshot` with `reason: "resync"` that contains only the resumed views.
* Unknown view names are ignored.

### unsubscribe

```json theme={null}
{ "op": "unsubscribe", "id": "board" }
```

| Message | Effect |
| - | - |
| `{ "op": "unsubscribe", "id": "board" }` | Remove the subscription `board` |
| `{ "op": "unsubscribe", "id": "board", "view": "new" }` | Remove the view `new` from `board` |
| `{ "op": "unsubscribe", "view": "new" }` | Remove the view `new` from every subscription |
| `{ "op": "unsubscribe" }` | Remove every subscription on this connection |

A subscription whose last view is removed is deleted. There is no reply.

### ping

```json theme={null}
{ "op": "ping" }
```

The server answers `{"type":"pong"}`. This is optional: the server already sends WebSocket protocol pings (see [Connection lifecycle](#connection-lifecycle)).

## Server messages

| `type` | When |
| - | - |
| `snapshot` | After `subscribe` and `resume`, about every 30 seconds, and after the connection recovers from back-pressure |
| `token-added` | A token entered a view |
| `token-updated` | A token in a view changed |
| `token-removed` | A token left a view |
| `error` | A client message was rejected |
| `pong` | Reply to `ping` |

### snapshot

```json theme={null}
{
  "type": "snapshot",
  "id": "board",
  "reason": "initial",
  "data": {
    "new": { "data": [{ "address": "0x8f3a...a2b3", "chainId": "evm:8453", "symbol": "OTTER", "...": "..." }] },
    "bonding": { "data": [] }
  }
}
```

| Field | Type | Description |
| - | - | - |
| `id` | string | Subscription id |
| `reason` | `"initial"` \| `"resync"` | `initial` follows a `subscribe` and contains every view of the subscription. `resync` is a full replacement for the views it contains, which can be a subset. |
| `data` | object | One key per view, each `{ "data": PulseToken[] }` in rank order. Tokens are [Pulse token objects](https://sonar-cf3aeac7.mintlify.site/pulse/token-object.md). |

**Replace** each view listed in a snapshot with its new list. Views not listed in a resync are unchanged.

A `resync` snapshot is sent:

1. **On `resume`**, for the resumed views only.
2. **About every 30 seconds**, for every view of the subscription that is not paused. The server re-ranks active views against the database on this interval, which corrects any drift.
3. **After back-pressure.** If more than about 4 MiB of messages are waiting to be sent to your connection, the server stops sending it events. Once the backlog drops below about 2 MiB, it sends a resync of every view that is not paused.

### token-added

```json theme={null}
{
  "type": "token-added",
  "id": "board",
  "view": "new",
  "token": { "address": "0x8f3a5b1c9e2d47a0b6c3e4f5a6b7c8d9e0f1a2b3", "chainId": "evm:8453", "symbol": "OTTER", "...": "..." }
}
```

| Field | Type | Description |
| - | - | - |
| `id` | string | Subscription id |
| `view` | string | View name |
| `token` | object | The full [Pulse token object](https://sonar-cf3aeac7.mintlify.site/pulse/token-object.md) |

The token entered the view's top `limit` because it was just launched or just bonded. **No position is sent.** Insert the token and re-sort the view by its sort. If the addition pushed another token out, that token gets its own `token-removed`.

Tokens that start to match a view only because their stats changed (for example volume rising above a filter) are not sent as `token-added`. They appear in the next periodic `resync` snapshot.

### token-updated

```json theme={null}
{
  "type": "token-updated",
  "id": "board",
  "view": "new",
  "token": { "address": "0x8f3a5b1c9e2d47a0b6c3e4f5a6b7c8d9e0f1a2b3", "chainId": "evm:8453", "volume1hUSD": 41500, "...": "..." }
}
```

Same fields as `token-added`. The token's stats or metadata changed.

* `token` is the **full** token object, not a diff. Replace the stored token by its key.
* Re-sort the view afterwards, because the change can move the token.
* Updates are throttled to at most one per token per view about every 50 ms. Changes in between are merged and the latest state is sent.
* Metadata refreshes (logo, description, socials, name, symbol) also produce `token-updated`.
* A newly launched token first appears with the data seen at launch. A fuller version usually follows as `token-updated` about 150 ms later, and a logo that shows up within the token's first 5 minutes is also pushed as an update.

### token-removed

```json theme={null}
{ "type": "token-removed", "id": "board", "view": "bonding", "key": "evm:8453|0x2c7e9a14b5d3f60a8e1c4b7d92f0a3e5c6b8d1f4" }
```

| Field | Type | Description |
| - | - | - |
| `id` | string | Subscription id |
| `view` | string | View name |
| `key` | string | [Token key](https://sonar-cf3aeac7.mintlify.site/pulse/token-object.md#token-key): `<chainId>\|<lowercase address>` |

Remove the token whose `chainId` and lowercase `address` build the same key. When a token bonds, for example, it leaves `bonding` with `token-removed` and enters `bonded` with `token-added`.

### error

```json theme={null}
{
  "type": "error",
  "id": "3b0a6f9e-6a1c-4d0e-9a51-0c2f3f7a8d14",
  "message": "Invalid pulse subscription",
  "issues": ["views.0.chainId: unsupported chain solana:solana", "views.1.name: a is used twice"]
}
```

| Field | Type | Description |
| - | - | - |
| `message` | string | What went wrong |
| `issues` | string\[], optional | Each problem as `"<path>: <message>"` |
| `id` | string, optional | Subscription id, when the error belongs to a subscribe request that passed the basic shape check |

The connection stays open after an error. See [Errors](#errors).

### pong

```json theme={null}
{ "type": "pong" }
```

## Compression

Set `"compressed": true` in `params` to receive this subscription's **snapshot** messages as **binary** WebSocket frames containing the gzip-compressed JSON. Every other message (`token-*`, `error`, `pong`) is always sent as plain JSON text.

```javascript theme={null}
// Browser
ws.binaryType = 'arraybuffer';
ws.onmessage = async (event) => {
  const text =
    typeof event.data === 'string'
      ? event.data
      : await new Response(
          new Blob([event.data]).stream().pipeThrough(new DecompressionStream('gzip')),
        ).text();
  handle(JSON.parse(text));
};
```

In Node.js, `zlib.gunzipSync(Buffer.from(data)).toString()` does the same.

## Limits

| Limit | Value |
| - | - |
| Views per connection, across all subscriptions | 10 |
| Views per subscribe request | 1 to 10 |
| Default `limit` per view | 50 |
| Maximum `limit` per view | 100 |
| `offset` | not available |
| Subscription `id` | 1 to 128 characters |
| Client message size | 64 KiB (larger messages close the connection with code 1009) |
| Server protocol ping interval | 30 seconds |
| `token-updated` per token per view | at most one about every 50 ms |
| Periodic resync | about every 30 seconds |

When you replace a subscription (same `id`), its current views do not count against the 10-view limit.

## Connection lifecycle

* **Heartbeat.** The server sends a WebSocket protocol ping every 30 seconds. A connection that has not answered the previous ping with a pong is closed. Browsers and common WebSocket libraries answer pings automatically.
* **Restarts.** When the server restarts, it closes connections with code **1012** and reason `Server restarting, reconnect`. While it is shutting down, new connection attempts get HTTP 503.
* **Reconnecting.** Subscriptions do not survive a reconnect. After any close, reconnect with exponential backoff (for example `min(30 s, 1 s × 2^attempt)`), send your `subscribe` again, and rebuild your state from the new initial snapshot.

## Building a client

Keep one ordered list per view, and apply messages like this:

| Message | Action |
| - | - |
| `snapshot` | Replace every view listed in `data` with its list |
| `token-added`, `token-updated` | Upsert the token by key, then re-sort the view |
| `token-removed` | Delete the token with that key |
| `error` | Show `message` and `issues` |
| close | Reconnect with backoff and subscribe again |

To re-sort, use the view's sort: your `sortBy` and `sortOrder`, or the model's preset sort (`new`: `createdAt` desc, `bonding`: `bondingPercentage` desc, `bonded`: `bondedAt` desc, `trending`: `feesPaid15minUSD` desc). Use the camelCase field name from the token object, and keep tokens with a `null` value last.

This runs in a browser or in Node.js 22 and later:

```javascript theme={null}
const URL = 'wss://api.example.com/v1/ws/pulse';

const subscription = {
  op: 'subscribe',
  id: 'board',
  params: {
    chainId: ['evm:8453'],
    views: [
      { name: 'new', model: 'new', limit: 50 },
      { name: 'bonding', model: 'bonding', limit: 50 },
      { name: 'bonded', model: 'bonded', limit: 50 },
    ],
  },
};

// Sort per view, using camelCase token fields.
const sorts = {
  new: { field: 'createdAt', order: 'desc' },
  bonding: { field: 'bondingPercentage', order: 'desc' },
  bonded: { field: 'bondedAt', order: 'desc' },
};

const views = new Map(); // view name -> tokens in rank order

const keyOf = (token) => `${token.chainId}|${token.address}`.toLowerCase();
const valueOf = (value) => (typeof value === 'string' ? Date.parse(value) : value);

function sortView(name) {
  const { field, order } = sorts[name];
  const direction = order === 'asc' ? 1 : -1;
  views.get(name).sort((a, b) => {
    const x = valueOf(a[field]);
    const y = valueOf(b[field]);
    if (x === y) return 0;
    if (x === null || x === undefined) return 1; // nulls last
    if (y === null || y === undefined) return -1;
    return (x < y ? -1 : 1) * direction;
  });
}

function handle(message) {
  switch (message.type) {
    case 'snapshot':
      for (const [name, { data }] of Object.entries(message.data)) {
        views.set(name, data);
        sortView(name);
      }
      break;
    case 'token-added':
    case 'token-updated': {
      const list = views.get(message.view);
      if (!list) break;
      const key = keyOf(message.token);
      const index = list.findIndex((token) => keyOf(token) === key);
      if (index === -1) list.push(message.token);
      else list[index] = message.token;
      sortView(message.view);
      break;
    }
    case 'token-removed': {
      const list = views.get(message.view);
      if (!list) break;
      const key = message.key.toLowerCase();
      views.set(message.view, list.filter((token) => keyOf(token) !== key));
      break;
    }
    case 'error':
      console.error(message.message, message.issues ?? []);
      break;
  }
}

let attempt = 0;

function connect() {
  const ws = new WebSocket(URL);
  ws.onopen = () => {
    attempt = 0;
    ws.send(JSON.stringify(subscription));
  };
  ws.onmessage = (event) => {
    handle(JSON.parse(event.data));
    console.log(views.get('new')?.slice(0, 5).map((token) => token.symbol));
  };
  ws.onclose = () => {
    const delay = Math.min(30_000, 1_000 * 2 ** attempt++);
    setTimeout(connect, delay);
  };
}

connect();
```

## Session transcript

`→` is a client message, `←` a server message. Token objects are shortened.

```text theme={null}
→ connect wss://api.example.com/v1/ws/pulse
→ {"op":"subscribe","id":"board","params":{"chainId":["evm:8453"],"compressed":false,
     "views":[{"name":"new","model":"new","limit":50},
              {"name":"bonding","model":"bonding","limit":50},
              {"name":"bonded","model":"bonded","limit":50}]}}
← {"type":"snapshot","id":"board","reason":"initial","data":{"new":{"data":[…]},"bonding":{"data":[…]},"bonded":{"data":[…]}}}
← {"type":"token-added","id":"board","view":"new","token":{"address":"0x8f3a…a2b3","chainId":"evm:8453",…}}
← {"type":"token-removed","id":"board","view":"new","key":"evm:8453|0x51d0…77c3"}        (pushed out of the top 50)
← {"type":"token-updated","id":"board","view":"new","token":{…full object, logo now set…}}
← {"type":"token-removed","id":"board","view":"bonding","key":"evm:8453|0x2c7e…d1f4"}    (token bonded)
← {"type":"token-added","id":"board","view":"bonded","token":{…"bonded":true…}}
→ {"op":"pause","id":"board","views":["bonded"]}
→ {"op":"resume","id":"board","views":["bonded"]}
← {"type":"snapshot","id":"board","reason":"resync","data":{"bonded":{"data":[…]}}}
← {"type":"snapshot","id":"board","reason":"resync","data":{"new":{…},"bonding":{…},"bonded":{…}}}   (about every 30 s)
→ {"op":"ping"}
← {"type":"pong"}
→ {"op":"unsubscribe","id":"board","view":"new"}
→ {"op":"unsubscribe"}
```

## Errors

| `message` | Cause |
| - | - |
| `Messages must be JSON text` | Binary frame or invalid JSON |
| `Unknown op <op>` | Missing or unrecognised `op` |
| `Invalid pulse subscription` | `subscribe` failed validation. Details are in `issues`. |
| `Invalid pause message` | Malformed `pause` or `resume` |
| `Invalid unsubscribe message` | Malformed `unsubscribe` |
| `Pulse is temporarily unavailable, try again` | The server could not process the message. Retry. |

`Invalid pulse subscription` comes in two forms:

* **Shape errors** (wrong types, `limit` above 100, more than 10 views): the issue paths start with `params.`, and the error has **no** `id`.

  ```json theme={null}
  { "type": "error", "message": "Invalid pulse subscription", "issues": ["params.views.0.limit: Too big: expected number to be <=100"] }
  ```

* **View errors** (unknown filters, unsupported chains, duplicate names, `offset` above 0, too many views on the connection): the issue paths start with `views.`, except the connection limit, which is reported as the plain issue `at most 10 views per connection`. The error carries the subscription `id`, or the generated UUID if you did not send one. The full list is in [Filters and sortable fields](https://sonar-cf3aeac7.mintlify.site/pulse/filters-and-fields.md#validation-messages).

  ```json theme={null}
  { "type": "error", "id": "board", "message": "Invalid pulse subscription", "issues": ["views.0.filters.holders_count: not supported yet"] }
  ```

A rejected `subscribe` does not change existing subscriptions.

A client message larger than 64 KiB is not answered with an `error`: the server closes the connection with WebSocket close code **1009** (message too big).


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