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

# Real-Time Data

> Subscribe to DexBuilder Event Contracts real-time data streams.

DexBuilder provides real-time Event Contracts data through the WebSocket Broker. Public market-data channels do not require authentication.

## Connection

Event Contracts:

```text theme={null}
wss://broker.dexbuilder.com/ws/dex-builder/event-contracts
```

For Event Contracts, use the separate product connection:

```text theme={null}
wss://broker.dexbuilder.com/ws/dex-builder/event-contracts
```

The examples below use the Event Contracts channel prefix `pred`. Event Contracts uses the corresponding `ec` prefix.

## Subscribe to a Public Channel

A subscription request contains a request timestamp `t`, a client `id`, an operation, a channel, and channel-specific items.

```json theme={null}
{
  "t": 1720000000123,
  "id": "sub-1",
  "op": "subscribe",
  "ch": "ec.bbo",
  "payload": {
    "items": [
      {
        "token_id": "ge_token-yes"
      }
    ]
  }
}
```

The server acknowledges the request and then sends channel data. Public channels require `items`; `all: true` is reserved for private channels.

## Public Channels

| Channel | Subscription item | Use |
| - | - | - |
| `ec.trades` | `condition_id` | Matched trades |
| `ec.depth` | `token_id`, `level` | Full order-book snapshots |
| `ec.bbo` | `token_id` | Best bid/ask and last price |
| `ec.status` | `market_id` | Market status and outcome prices |
| `ec.cpi` | `symbol`, `interval` | Reference price updates |
| `ec.candlestick` | `symbol`, `interval` | Candlestick updates |
| `ec.oc_price` | `slug` or `market_id` | Price-to-beat and final-price updates |

## Response Envelope

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.bbo",
  "err": null,
  "result": {
    "condition_id": "ge_condition-1",
    "token_id": "ge_token-yes",
    "bid_px": "0.4400",
    "ask_px": "0.4600",
    "last_px": "0.4500",
    "ts": 1720000000123
  }
}
```

Channels with cached state can send `type: "snapshot"` before subsequent `update` messages. Order-book snapshots contain full `bids` and `asks` arrays; they are not deltas.

## CPI Example

Subscribe to a crypto reference price:

```json theme={null}
{
  "t": 1720000000123,
  "id": "cpi-1",
  "op": "subscribe",
  "ch": "ec.cpi",
  "payload": {
    "items": [
      {
        "symbol": "btcusdt",
        "interval": "1m"
      }
    ]
  }
}
```

Example update:

```json theme={null}
{
  "t": 1720000000124,
  "trace_id": "trace-1",
  "type": "update",
  "ch": "ec.cpi",
  "err": null,
  "result": {
    "symbol": "btcusdt",
    "interval": "1m",
    "price": "100000.10",
    "price_timestamp": "1720000000123",
    "ts": 1720000000123
  }
}
```

## Connection Recovery

When a connection is interrupted:

1. reconnect with backoff;
2. restore public subscriptions;
3. use REST endpoints such as `/api/v4/event_contracts/markets` and `/api/v4/event_contracts/tokens/{token_id}/ticker` to refresh authoritative state;
4. deduplicate repeated updates using the channel key and timestamp.

See [WebSocket Protocol](https://dexbuilder.mintlify.site/en/event-contracts/websocket/protocol.md), [Public Channels](https://dexbuilder.mintlify.site/en/event-contracts/websocket/public-channels.md), and [WebSocket Authentication](https://dexbuilder.mintlify.site/en/event-contracts/websocket/authentication.md) for the complete protocol.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.