# Real-time streams.

> Source: https://implyra.com/docs/streaming
> Implyra API docs · Core concepts · Real-time streams

Subscribe to market activity with server-sent events on your assigned stream service.

Transport: SSE

## Connect to a market stream

`GET /markets/:slug/stream`

The stream service uses a separate base URL from REST. Market streams publish an initial snapshot, new trades, and keepalive events. Replace example-market with a slug returned by discovery.

> **Browser connections.** The JavaScript example requires a deployment that allows your browser origin and the requested stream. EventSource cannot send custom authorization headers; use the access mechanism supplied during onboarding.

**Follow one market**

```sh
curl --no-buffer --fail-with-body \
  -H "Accept: text/event-stream" \
  "$IMPLYRA_STREAM_URL/markets/example-market/stream"
```

```js
const streamBaseUrl = "https://your-stream-endpoint.example";
const slug = "example-market";
const stream = new EventSource(
  streamBaseUrl + "/markets/" + encodeURIComponent(slug) + "/stream"
);

stream.addEventListener("init", (event) => {
  console.log("Initial snapshot", JSON.parse(event.data));
});

stream.addEventListener("trade", (event) => {
  console.log("New trade", JSON.parse(event.data));
});

stream.onerror = () => {
  console.warn("Stream interrupted; EventSource will reconnect");
};

// Call when the view unmounts or the subscription changes.
const disconnect = () => stream.close();
```

## Market stream events

Listen to named events with addEventListener. A generic onmessage handler alone does not consume events that have an explicit event name.

| Name | Type | Description |
| --- | --- | --- |
| `init` | Snapshot | Initial market data after connecting. Handle this separately from incremental trade events. |
| `trade` | Trade | A trading activity update for the subscribed market. |
| `keepalive` | Every 15 seconds | Maintains the market stream connection during quiet periods. |

## Available stream routes

| Name | Type | Description |
| --- | --- | --- |
| `GET /trades/stream` | system · trade | Global enriched trades with a minimum trade value of $100. |
| `GET /smart-money/public/stream` | system · trade | Public smart-money trade activity. |
| `GET /top-trader-signals/stream` | system · backfill · signal | Top-trader signals. Supports since, minSharpe, minWinRate, minPnl, and traderTier filters. Backfill payloads are arrays. |
| `GET /wallets/stream?ticket=…` | system · trade | User-specific tracked-wallet activity. Requires an authenticated session or a short-lived stream ticket. |

## Wallet stream tickets

Authenticated wallet integrations can request a ticket with POST /wallets/stream-ticket. The stream service accepts its klarity_access_token session cookie or a request header of the same name for this operation. That session is separate from REST deployment access.

The response is an object with a ticket string. Connect to /wallets/stream?ticket=... within 30 seconds. Tickets are single-use; obtain a new ticket before reconnecting a ticket-based wallet stream.

## Plan for reconnects

Close streams when a view is no longer active, and limit the number of simultaneous connections. On reconnect, refresh the relevant REST snapshot if your interface needs to reconcile missed activity.

Do not assume exactly-once delivery or universal replay. The top-trader signal stream supports a since parameter for backfill; other streams have their own event and recovery behavior.
