> TickerLayer documentation for AI agents and LLMs, the Markdown version of https://tickerlayer.com/docs/websocket
> REST base URL https://api.tickerlayer.com, API key in the `x-api-key` header. WebSocket wss://stream.tickerlayer.com?apiKey=YOUR_API_KEY.
> Any docs page reads as Markdown at its URL plus `.md`. Index: https://tickerlayer.com/llms.txt · Full API reference: https://tickerlayer.com/llms-full.txt

# WebSocket stream

One native WebSocket. Authenticate on connect, wait for ready, subscribe to channels, receive quote and trade frames. No Socket.IO.

## How it works

1. **Connect**: Open `wss://stream.tickerlayer.com/?apiKey=…`; the parameter name is exactly `apiKey`. The key is checked on this upgrade only, never on later frames ([Connection](https://tickerlayer.com/docs/websocket/connection), [Authentication](https://tickerlayer.com/docs/websocket/authentication)).
2. **Wait for ready**: The first frame is `{ "type": "system", "event": "ready" }`. Send nothing before it.
3. **Subscribe**: Send a JSON text frame with `action`, `channels` and `symbols`. The server replies with `subscribed` and, by default, a snapshot.
4. **Receive**: Live `quote` and `trade` frames arrive on those channels. Use `unsubscribe` and `ping` as needed.

## Try it live

Signed in with an active key? Pick an asset and a stream, add up to two symbols, and watch the latest tick update in place.

## Minimal example

The same flow in code. The [Quickstart](https://tickerlayer.com/docs/quickstart) walks through it step by step.

**Browser / Node**

```javascript
const ws = new WebSocket(
  "wss://stream.tickerlayer.com/?apiKey=" + encodeURIComponent(rawKey)
);

ws.onmessage = (ev) => {
  const msg = JSON.parse(String(ev.data));
  if (msg.type === "system" && msg.event === "ready") {
    ws.send(JSON.stringify({
      action: "subscribe",
      channels: ["crypto.quotes"],
      symbols: ["BTCUSD"],
    }));
    return;
  }
  console.log(msg); // quote | trade | system | error
};
```

## Supported channels

| Asset class | Channels | Example |
| --- | --- | --- |
| [Stocks](https://tickerlayer.com/docs/products/stocks) | `stocks.quotes` `stocks.trades` `stocks.agg` `stocks.status` | `US:KO` `DE:BMW` |
| [Forex](https://tickerlayer.com/docs/products/forex) | `forex.quotes` `forex.trades` | `EURUSD` |
| [Crypto](https://tickerlayer.com/docs/products/crypto) | `crypto.quotes` `crypto.trades` | `BTCUSD` |
| [Indices](https://tickerlayer.com/docs/rest/indices) | `indices.quotes` `indices.trades` | `US500` |
| [ETFs](https://tickerlayer.com/docs/rest/etfs) | `etfs.quotes` `etfs.trades` `etfs.agg` | `US500ETF` |
| [Commodities](https://tickerlayer.com/docs/products/commodities) | `commodities.quotes` `commodities.trades` | `XAUUSD` |
| [Bonds](https://tickerlayer.com/docs/products/bonds) | `bonds.quotes` | `US:10Y` |
| [Perpetuals](https://tickerlayer.com/docs/products/perpetuals) | `perpetuals.quotes` `perpetuals.marks` `perpetuals.trades` | `XAUUSDT` |
| [Futures CFDs](https://tickerlayer.com/docs/products/futures) | `futures.quotes` | `WTIUSD.C1` `XAUUSD.DEC26` |

- **`stocks.agg`:** Settled US OHLCV bars, from 1 minute to 1 day.
- **`etfs.agg`:** The same settled bars for US-listed ETFs, with ETF access.
- **`stocks.status`:** US trading halt and resume events.
- **`bonds.quotes`:** The latest daily yield on subscribe, then one frame per new observation.
- **`perpetuals.*`:** Composite top of book, mark price and trades, streamed on the Perpetuals Business plan.
- **`futures.quotes`:** Contract months, the C1-C3 chain and roll series, for accounts with Futures CFDs.
- **Forex raw line:** `SYMBOL.RAW` streams a single-venue line; see [Forex](https://tickerlayer.com/docs/products/forex#forex-raw-line).

Symbols come from the same registries as REST, and each channel needs its asset class on your plan.

## Deeper reference

- [Connection](https://tickerlayer.com/docs/websocket/connection): URL, upgrade outcomes and the ready frame.
- [Authentication](https://tickerlayer.com/docs/websocket/authentication): Why the key goes on the URL, and how that differs from REST.
- [Subscriptions](https://tickerlayer.com/docs/websocket/subscriptions): Subscribe, unsubscribe, ping, snapshots and limits.
- [Message types](https://tickerlayer.com/docs/websocket/messages): Every frame the stream sends, field by field.
- [Errors & troubleshooting](https://tickerlayer.com/docs/websocket/troubleshooting): Upgrade failures, error codes and common fixes.
