# Websocket

### Websocket URL

#### Mainnet

```url
wss://api.hydromancer.xyz/ws
```

#### Testnet

```
wss://api-testnet.hydromancer.xyz/ws
```

### Authentication

Include your API key as a query parameter in the connection URL:

```
wss://api.hydromancer.xyz/ws?token=your-api-key-here
```

### Subscribe

```
{ 
    "type": "subscribe",
    "subscription": {
        "type": "userFills",
        "addresses": ["0x742d35Cc6634C0532925a3b844Bc9e7595f7F2e2"]
    }
} 
```

### Unsubscribe

```
{ 
    "type": "unsubscribe",
    "subscription": {
        "type": "userFills",
        "addresses": ["0x742d35Cc6634C0532925a3b844Bc9e7595f7F2e2"]
    }
} 
```

### Live Message Chunking

For improved connection stability during high-volume periods, enable chunked message delivery by adding `liveFormat=chunked-v1` to your connection URL:

```
wss://api.hydromancer.xyz/ws?token=your-api-key&liveFormat=chunked-v1
```

For `chunked-v1` connections, large batched live messages (fills, orders, trades, etc.) are split by item count into smaller chunks with metadata (`chunk`, `totalChunks`, `batchId`) for reassembly. This is fully backward compatible — existing clients without `liveFormat` see no change.

See [Live Message Chunking](/readme/websocket/live-message-chunking.md) for full details.

### Heartbeats

To see if a client is still active the server will send a ping message every 60 seconds, please make sure to respond with a pong to keep the connection alive.

Server sends:

```json
{ 
    "type": "ping"
} 
```

Respond with:

```json
{ 
    "type": "pong"
} 
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hydromancer.xyz/readme/websocket.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
