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

# WebSocket Overview

> Real-time orderbook and trade streaming via WebSocket

## Connection

Connect to the WebSocket endpoint with your API key:

| Environment  | URL                                     |
| ------------ | --------------------------------------- |
| Local server | `ws://localhost:3847/ws`                |
| Hosted API   | `wss://api.pmxt.dev/ws?apiKey=YOUR_KEY` |

All messages are JSON text frames. A single connection supports multiple concurrent subscriptions.

## Protocol

### Subscribe

```json theme={null}
{ "id": "req-1", "action": "subscribe", "exchange": "polymarket", "method": "watchOrderBook", "args": ["OUTCOME_ID", 50] }
```

### Data event

```json theme={null}
{
  "event": "data",
  "id": "req-1",
  "method": "watchOrderBook",
  "symbol": "OUTCOME_ID",
  "source": "polymarket",
  "data": {
    "bids": [{ "price": 0.42, "size": 100 }],
    "asks": [{ "price": 0.58, "size": 200 }],
    "timestamp": 1778450010713
  }
}
```

### Unsubscribe

```json theme={null}
{ "id": "req-1", "action": "unsubscribe", "exchange": "polymarket", "method": "watchOrderBook", "args": ["OUTCOME_ID"] }
```

### Error

```json theme={null}
{ "event": "error", "id": "req-1", "error": { "message": "..." } }
```
