# Crypto price stream

Price changes pushed to you over a WebSocket or Server-Sent Events, on every plan.

`GET /v2/stream` pushes a message each time a price you follow changes, over Server-Sent Events (SSE) or a WebSocket. Every plan has it. Free allows 1 connection with up to 10 channels and a message every 5 seconds. Paid plans allow more connections and channels and send every second. [View pricing](/pricing) or [read the API reference](/docs).

## Connect

Send your API key in the `Authorization: Bearer` header when you open the connection. A browser cannot set that header on a WebSocket, so connect from a server and keep the key there. Without a key the answer is 401.

Pick what to follow with channels: `spot:bitcoin` for a coin price, `futures:BTC` for a futures price and `predictions:<id>` for a prediction market probability. Channel ids must exist: an unknown coin, futures symbol or prediction id is refused. Futures symbols are not case sensitive. SSE takes them in the query string. A WebSocket takes them in a message after it opens.

## Server-Sent Events

curl:

```bash
curl -sN -m 4 -H "Authorization: Bearer $COINPRICE_API_KEY" \
  "https://api.coinprice.dev/v2/stream?channels=spot:bitcoin,spot:ethereum"
```

Output, real run, 2026-11-24 05:53 UTC:

```text
data: {"channel":"spot:bitcoin","price":"60587.34315","at":"2026-11-24T05:53:01Z"}

data: {"channel":"spot:ethereum","price":"1706.200892","at":"2026-11-24T05:53:01Z"}

data: {"channel":"spot:bitcoin","price":"60587.61782","at":"2026-11-24T05:53:07Z"}

data: {"channel":"spot:ethereum","price":"1706.170929","at":"2026-11-24T05:53:07Z"}
```

## WebSocket

Send `{"subscribe": [...]}` to add channels and `{"unsubscribe": [...]}` to drop them. This example uses the `ws` package for Node.js, which can set the header.

JavaScript:

```javascript
import WebSocket from 'ws'

const ws = new WebSocket('wss://api.coinprice.dev/v2/stream', {
  headers: { Authorization: `Bearer ${process.env.COINPRICE_API_KEY}` },
})

ws.on('open', () => {
  ws.send(JSON.stringify({ subscribe: ['spot:bitcoin', 'spot:ethereum'] }))
})

ws.on('message', (data) => {
  const message = JSON.parse(data)
  if (message.error) return console.error(message.error, message.message)
  console.log(message.channel, message.price, message.at)
})

ws.on('close', (code) => console.log('closed', code))
```

Output, real run, 2026-11-24 05:53 UTC:

```text
spot:bitcoin 60584.95 2026-11-24T05:52:29Z
spot:ethereum 1706.14 2026-11-24T05:52:29Z
spot:bitcoin 60588.15 2026-11-24T05:52:30Z
spot:ethereum 1706.240843 2026-11-24T05:52:30Z
```

## Messages

| Field | Meaning |
|---|---|
| `channel` | The channel the price belongs to, for example `spot:bitcoin`. |
| `price` | The price as a decimal string. Spot and futures prices are in US dollars; a prediction channel carries its probability from 0 to 1. REST prices are JSON numbers; stream prices are strings. |
| `at` | When the price was seen, UTC, ISO 8601. |

A message is sent when a channel's price has changed since the last message for it, and at most once per interval for the connection. A quiet market sends nothing, and SSE adds a `: ping` comment every 15 seconds to keep the connection open.

## Limits by plan

| Plan | Connections | Channels per connection | Message every |
|---|---|---|---|
| Free | 1 | 10 | 5 seconds |
| Starter | 5 | 250 | 1 second |
| Basic | 20 | 250 | 1 second |
| Pro | 100 | 250 | 1 second |

Opening a connection counts as one call. Messages on it do not. Reconnecting counts again.

## Errors

| Where | error | When |
|---|---|---|
| Opening the connection | `unauthorized` | The key is missing or wrong (401). |
| Opening the connection | `rate_limited` | You already have as many connections open as your plan allows (429). |
| SSE, opening | `invalid_request` | A channel does not exist (an unknown coin, futures symbol or prediction id), or there are more channels than the plan allows (400). |
| WebSocket, after a subscribe | `invalid_request` | The message lists the `refused` channels, such as one that does not exist; the others are subscribed. |
| Open stream | `unauthorized` | The key was revoked or its plan changed. Reconnect. |
| Open stream | `quota_exceeded` | The month's calls ran out. The stream closes. |

An open stream re-checks its key once a minute.

## Reconnect

On a disconnect, wait and reconnect with a growing delay, then subscribe again. The first message for each channel arrives after you subscribe, with the latest price.

## Questions

**Which plans include the stream?** All four. Free has 1 connection of up to 10 channels and a message every 5 seconds. Starter, Basic and Pro send every second.

**Can I connect without an API key?** No. Send the key in the Authorization header when you open the connection. Without it the answer is 401.

**Does each price message use a call?** No. Opening a connection uses one call. The messages on it are free, and a reconnect uses one more call.

**Are stream prices in other currencies?** No. Stream prices are in US dollars. Use REST with vs_currencies for other currencies.

**Why are stream prices strings?** The stream sends each price as a decimal string. REST responses use JSON numbers.
