> ## 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.

# Manifold WebSocket

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

## Connection

Connect to the Manifold WebSocket endpoint:

```
wss://api.delphiterminal.co/ws/mani?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": ["Iz0lRpO85N", "SdZ6A2IZ88"],
  "message_types": ["prices", "orderbook", "trades"]
}
```

| Field           | Type   | Required | Description                                                                                                  |
| --------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------ |
| `action`        | string | Yes      | `subscribe` or `unsubscribe`                                                                                 |
| `market_ids`    | array  | Yes      | Array of Manifold market identifiers (slug 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": ["Iz0lRpO85N"]
}
```

## Message types

### Price messages

```json theme={"theme":"one-dark-pro"}
{
  "type": "prices",
  "data": {
    "venue": "MANI",
    "market_id": "Iz0lRpO85N",
    "server_time": 1774762511552,
    "ingest_time": 1774762511553,
    "payload": {
      "type": "Ticker",
      "Ticker": {
        "price": 0.67,
        "yes_bid": 0.66,
        "yes_ask": 0.68,
        "volume": 0,
        "open_interest": 0
      }
    }
  }
}
```

### Orderbook messages

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

### Trade messages

```json theme={"theme":"one-dark-pro"}
{
  "type": "trades",
  "data": {
    "venue": "MANI",
    "market_id": "Iz0lRpO85N",
    "server_time": 1774762511552,
    "payload": {
      "type": "Trade",
      "Trade": {
        "bet_id": "abc123",
        "outcome": "YES",
        "amount": 10.0,
        "shares": 14.82,
        "price": 0.676
      }
    }
  }
}
```

## Full example

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

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

  ws.send(JSON.stringify({
    action: "subscribe",
    market_ids: ["Iz0lRpO85N"],
    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` (Manifold market identifier) to subscribe
* Manifold data is sourced via REST polling (5–15s intervals), not native WebSocket
* Messages are only sent for markets you have explicitly subscribed to
* Trades must be explicitly requested (not included in the default subscription)
