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

# Connection

> WebSocket endpoint and network options

## WebSocket endpoint

```
wss://hyper.polynode.dev/ws?key={api_key}
```

Pass your API key as a query parameter. Keys are prefixed with `pn_live_`.

## Networks

| Network | Endpoint                      | Volume                           | Description                  |
| ------- | ----------------------------- | -------------------------------- | ---------------------------- |
| Mainnet | `wss://hyper.polynode.dev/ws` | \~6,500 events/sec (both layers) | HyperLiquid production chain |

## Latency

hypernode delivers committed transactions \~1 second before HyperLiquid's own public API.

## Keep-alive

The server sends WebSocket ping frames every 30 seconds. Your client must respond with pong within 90 seconds or the connection is closed. Most WebSocket libraries handle this automatically.

You can also send application-level pings:

```json theme={null}
{"action": "ping"}
```

Response:

```json theme={null}
{"action": "pong"}
```

## Reconnection

There is no event replay or gap-fill mechanism. If your connection drops, you may miss events during the disconnection window. Reconnect immediately with exponential backoff:

```typescript theme={null}
let delay = 500;
ws.onclose = () => {
  setTimeout(() => {
    delay = Math.min(delay * 2, 10000);
    connect(); // re-establish and re-subscribe
  }, delay);
};
```

On successful reconnect, reset your delay and re-send all subscription messages.

## Full Python example

A complete example that connects, authenticates, subscribes to fills, and processes events:

```python theme={null}
import asyncio
import json
import websockets

API_KEY = "pn_live_..."
URL = f"wss://hyper.polynode.dev/ws?key={API_KEY}"

async def main():
    async with websockets.connect(URL) as ws:
        # Subscribe to all fills across every market
        await ws.send(json.dumps({
            "action": "subscribe",
            "filters": {"action_types": ["fill"]}
        }))

        async for raw in ws:
            event = json.loads(raw)

            # Ignore the subscription ack
            if event.get("action") == "subscribed":
                print(f"Subscribed (sub_id={event.get('sub_id')})")
                continue

            if event.get("type") == "fill":
                data = event["data"]
                print(f"{data['coin']} {data['sz']}@{data['px']} {data['dir']}")

asyncio.run(main())
```

Install the websockets library with `pip install websockets` (not `pip install websocket`).

### Subscription acknowledgement

After a successful subscribe, the server sends one acknowledgement message before any events:

```json theme={null}
{
  "action": "subscribed",
  "id": "default",
  "sub_id": 8,
  "total_subs": 3
}
```

Match on `event.get("action") == "subscribed"` and skip it, then process events by `event["type"]`.
