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

# Realtime Stream

> Websocket subscriptions for event, market, and standardized trade updates

The API service exposes a websocket stream at `ws://<api-host>/ws` by default. If `API_WEBSOCKET_PATH` is overridden in deployment, use that configured path instead.

## Subscribe

Send a JSON message after connecting:

```json theme={null}
{
  "action": "subscribe",
  "channels": ["events", "markets", "trades"]
}
```

Available channels:

* `events`: emits `catalog.event` messages with `created`, `updated`, or `closed`
* `markets`: emits `catalog.market` messages with `created`, `updated`, or `closed`
* `trades`: emits rebroadcast standardized trade messages as `trade`

## Example client

```js theme={null}
const ws = new WebSocket("ws://127.0.0.1:3001/ws");

ws.addEventListener("open", () => {
  ws.send(JSON.stringify({
    action: "subscribe",
    channels: ["events", "markets", "trades"],
  }));
});

ws.addEventListener("message", (event) => {
  const message = JSON.parse(event.data);
  console.log(message.type, message.action ?? null, message.data);
});
```
