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

# Prediction Markets Datastream

> Subscribe to live Kalshi and Polymarket trades, prices, quotes, orderbooks, and volume over the Solana Tracker Datastream WebSocket.

<Info>
  **Public Beta** — Prediction market rooms use the same Datastream hub as other Solana Tracker streams.\
  Connect to `wss://datastream.solanatracker.io/{apiKey}` with your Data API key.
</Info>

Instead of polling the [Prediction Markets REST API](/guides/prediction-markets), join `pm:*` rooms and receive trades, prices, books, and volume as they happen.

Delivery is at-least-once across failover — deduplicate with `data.sourceId` / `tradeId` when present.

Room `data` is **flat**: payload fields sit at the top level beside `type`, `channel`, `exchange`, `marketId`, and `timestamp`.

***

## Connecting

```javascript theme={null}
const ws = new WebSocket("wss://datastream.solanatracker.io/YOUR_API_KEY");

ws.onopen = () => {
  ws.send(JSON.stringify({ type: "join", room: "pm:trades" }));
  ws.send(JSON.stringify({
    type: "join",
    room: "pm:market:polymarket:YOUR_TOKEN_ID:prices"
  }));
};

ws.onmessage = (event) => {
  const msg = JSON.parse(event.data);
  if (msg.type === "message") console.log(msg.room, msg.data);
};
```

Join / leave:

```json theme={null}
{ "type": "join", "room": "pm:trades" }
{ "type": "leave", "room": "pm:trades" }
```

***

## Room types

| Room                                       | Purpose                                               |
| ------------------------------------------ | ----------------------------------------------------- |
| `pm:trades`                                | Full trade tape (all exchanges)                       |
| `pm:trades:significant`                    | Trades with **notional ≥ \$25**                       |
| `pm:{exchange}:trades`                     | e.g. `pm:polymarket:trades`                           |
| `pm:market:{exchange}:{marketId}:trades`   | Single-market tape                                    |
| `pm:event:{exchange}:{eventId}:trades`     | All markets under one event                           |
| `pm:market:{exchange}:{tokenId}:prices`    | Live top-of-book mid (+ `displayPrice`)               |
| `pm:market:{exchange}:{tokenId}:quotes`    | Streaming size-aware VWAP ladder                      |
| `pm:market:{exchange}:{tokenId}:orderbook` | Full book snapshots                                   |
| `pm:event:{exchange}:{eventId}:volume`     | Live cumulative USD volume for an event               |
| `pm:market:{exchange}:{tokenId}:volume`    | Live cumulative USD volume for one outcome            |
| `pm:crypto:{asset}`                        | Chainlink underlying (BTC/ETH/…) — not outcome chance |
| `pm:market_lifecycle` / `pm:resolution`    | Lifecycle and resolution fan-out                      |

There is **no** broad `pm:prices` firehose — prices, quotes, orderbooks, and volume are market- or event-scoped only.

`notionalUsd` is `price × quantity` (USD). The significant room uses threshold **\$25**.

Event rooms fan out under **every** identity on the payload (`eventId`, `eventSlug`, `gammaEventId`, Kalshi `eventTicker`), so slug-based and gamma-id joins both work.

***

## Volume example

Crypto 5m windows — join with the **event slug**:

```json theme={null}
{ "type": "join", "room": "pm:event:polymarket:btc-updown-5m-1785347100:volume" }
```

```json theme={null}
{
  "type": "message",
  "room": "pm:event:polymarket:btc-updown-5m-1785347100:volume",
  "data": {
    "type": "volume",
    "channel": "volume",
    "exchange": "polymarket",
    "marketId": "{tokenId}",
    "timestamp": 1785347120123,
    "eventId": "btc-updown-5m-1785347100",
    "volume": 48210.55,
    "marketVolume": 24105.27,
    "delta": 42.5
  }
}
```

Volume frames are latest-wins. Fields: `volume` (event total when `eventId` is set), `marketVolume`, `delta`, `eventId`.

***

## Quotes vs REST

Join `pm:market:polymarket:{tokenId}:quotes` for a streaming size-aware VWAP ladder. For arbitrary sizes use REST `GET /v1/markets/{id}/quote` on `prediction-market-api.solanatracker.io`.

***

## Prices vs crypto underlying

| Feed           | Room                                             | Meaning              |
| -------------- | ------------------------------------------------ | -------------------- |
| Outcome chance | `pm:market:polymarket:{tokenId}:prices`          | CLOB top-of-book mid |
| Underlying     | `pm:crypto:{asset}` / `pm:crypto:{asset}:prices` | Chainlink USD ticks  |

***

## IDs

* Room segments are **lowercase**.
* Polymarket market rooms require decimal **CLOB token IDs** (not `0x` condition ids).
* Kalshi tickers appear uppercase in many REST payloads but **lowercase** in room names.

***

## API reference

In the **Datastream** nav, Prediction Market rooms are grouped as:

| Group                          | Rooms                                                          |
| ------------------------------ | -------------------------------------------------------------- |
| Prediction Markets — Trades    | `pm:trades`, significant, exchange / market / event trades     |
| Prediction Markets — Prices    | market prices, quotes, orderbook                               |
| Prediction Markets — Volume    | event and market volume                                        |
| Prediction Markets — Lifecycle | lifecycle and resolution                                       |
| Prediction Markets — Crypto    | `pm:crypto:{asset}`                                            |
| Prediction Markets — Feeds     | exchange, market, event, type, category, series, status, sport |
