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

# WebSocket Streaming

> Live Cardano prices, swaps, and dApp events over STOMP

Stream live market data instead of polling. Nexus exposes a SockJS + STOMP WebSocket at `/ws/market` that relays token prices, DEX swaps, and dApp blueprint events. Market-data topics broadcast on a 10 second interval, so a subscriber receives a current snapshot on subscribe and then a push every 10 seconds rather than one message per on-chain event.

There are two ways to get WebSocket access:

1. **Included with your plan.** Scale, Enterprise, and Unlimited plans include streaming using the plan's own connection and message limits. (Builder and Growth do not include WebSocket access by default.)
2. **A WebSocket package**, attached per API key, which adds streaming to a plan that doesn't include it or overrides the per-key limits:

| Package   | Concurrent connections | Messages / mo |
| --------- | ---------------------- | ------------- |
| Starter   | 2                      | 100,000       |
| Pro       | 10                     | 2,000,000     |
| Unlimited | Unlimited              | Unlimited     |

<Note>
  Enterprise includes **WebSocket Unlimited**. Plan access and per-key packages are managed from your account.
</Note>

## Connecting

* **Endpoint:** `wss://nexus.gerowallet.io/ws/market` (SockJS)
* **Protocol:** STOMP
* **Auth:** API key via `?access_token=nxs_…` query parameter or `Authorization: Bearer nxs_…` header

Access is checked at connection time. Connections without an allowed package/tier are rejected during the handshake; exceeding your concurrent-connection or monthly-message quota caps or closes the connection.

## Topics

Subscribe to these STOMP destinations (server → client):

| Destination                      | Streams                                                                     |
| -------------------------------- | --------------------------------------------------------------------------- |
| `/topic/market/prices`           | All token prices - sends a current snapshot on subscribe, then live updates |
| `/topic/market/prices/{assetId}` | A single token's price - snapshot on subscribe, then updates                |
| `/topic/swaps`                   | Global DEX swap events (executed swaps, cancellations, limit-order fills)   |
| `/topic/dapp/{id}/events`        | Events for a registered [blueprint](/docs/addons/market-data) dApp               |

Client → server control:

| Destination               | Purpose                                                      |
| ------------------------- | ------------------------------------------------------------ |
| `/app/market/unsubscribe` | Unsubscribe from a token's price stream (send the `assetId`) |

## Example

```javascript theme={null}
import SockJS from 'sockjs-client';
import { Client } from '@stomp/stompjs';

const client = new Client({
  webSocketFactory: () =>
    new SockJS('https://nexus.gerowallet.io/ws/market?access_token=nxs_your_api_key_here'),
  onConnect: () => {
    // Live price for one token (current snapshot arrives first)
    client.subscribe('/topic/market/prices/lovelace', (msg) =>
      console.log('price', JSON.parse(msg.body)),
    );
    // Global swap feed
    client.subscribe('/topic/swaps', (msg) =>
      console.log('swap', JSON.parse(msg.body)),
    );
  },
});

client.activate();
```

<Note>
  Each delivered message counts toward your package's monthly message quota. Subscribe only to the tokens/feeds you need; use `/app/market/unsubscribe` when you no longer need a per-token stream.
</Note>
