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

# Opinion WebSocket

> Real-time price, orderbook, and trade streaming for Opinion prediction markets

## Connection

Connect to the Opinion WebSocket endpoint:

```
wss://api.delphiterminal.co/ws/opnm?api_key=YOUR_API_KEY
```

| Property         | Value                     |
| ---------------- | ------------------------- |
| Protocol         | WebSocket (wss\://)       |
| Authentication   | `api_key` query parameter |
| Keepalive        | Ping every 54 seconds     |
| Timeout          | 60 seconds without pong   |
| Max Message Size | 16 KB                     |

## Subscribing to markets

Once connected, send a JSON message to subscribe using `market_id`:

```json theme={"theme":"one-dark-pro"}
{
  "action": "subscribe",
  "market_ids": ["10702", "10705"],
  "message_types": ["prices", "orderbook", "trades"]
}
```

| Field           | Type   | Required | Description                                                                                                  |
| --------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------ |
| `action`        | string | Yes      | `subscribe` or `unsubscribe`                                                                                 |
| `market_ids`    | array  | Yes      | Array of Opinion market identifiers (numeric strings)                                                        |
| `message_types` | array  | No       | `["prices"]`, `["orderbook"]`, `["trades"]`, or any combination. Defaults to prices and orderbook if omitted |

## Unsubscribing

```json theme={"theme":"one-dark-pro"}
{
  "action": "unsubscribe",
  "market_ids": ["10702"]
}
```

## Message types

### Price messages

```json theme={"theme":"one-dark-pro"}
{
  "type": "prices",
  "data": {
    "venue": "OPNM",
    "market_id": "10702",
    "server_time": 1774762511552,
    "ingest_time": 1774762511553,
    "payload": {
      "type": "Ticker",
      "Ticker": {
        "price": 0.45,
        "yes_bid": 0.44,
        "yes_ask": 0.46,
        "volume": 0,
        "open_interest": 0
      }
    }
  }
}
```

### Orderbook messages

```json theme={"theme":"one-dark-pro"}
{
  "type": "orderbook",
  "data": {
    "exchange": "OPNM",
    "market_id": "10702",
    "yes_side": [0, 0, 100, 200],
    "no_side": [150, 100, 0, 0],
    "server_time": "2026-03-29T12:00:00Z"
  }
}
```

### Trade messages

```json theme={"theme":"one-dark-pro"}
{
  "type": "trades",
  "data": {
    "venue": "OPNM",
    "market_id": "10702",
    "server_time": 1774762511552,
    "payload": {
      "type": "Trade",
      "Trade": {
        "yes_price": 0.45,
        "no_price": 0.55,
        "count": 10,
        "taker_side": "yes"
      }
    }
  }
}
```

## Full example

```javascript theme={"theme":"one-dark-pro"}
const ws = new WebSocket("wss://api.delphiterminal.co/ws/opnm?api_key=YOUR_API_KEY");

ws.onopen = () => {
  console.log("Connected to Opinion WebSocket");

  ws.send(JSON.stringify({
    action: "subscribe",
    market_ids: ["10702"],
    message_types: ["prices", "orderbook", "trades"]
  }));
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);

  if (data.type === "prices") {
    console.log("Price update:", data.data);
  } else if (data.type === "orderbook") {
    console.log("Orderbook update:", data.data);
  } else if (data.type === "trades") {
    console.log("Trade:", data.data);
  }
};

ws.onclose = () => console.log("Disconnected");
ws.onerror = (error) => console.error("WebSocket error:", error);
```

## Important notes

* **Authentication required** via `api_key` query parameter
* Use `market_id` (Opinion market identifier) to subscribe
* Messages are only sent for markets you have explicitly subscribed to
* Multiple markets can be subscribed in a single message
* Trades must be explicitly requested (not included in the default subscription)
