# Connection & Subscription

Lynx provides a single unified WebSocket endpoint for all channel categories — public market data, on-chain explorer events, and per-user updates.

> **No authentication required.** User channels are subscribed by `address`; any address is publicly observable.

## Endpoints

| Surface  | URL                       |
| -------- | ------------------------- |
| Standard | `ws://10.34.8.77:8481/v1` |

## Connection Rules

| Rule               | Detail                                                                                                 |
| ------------------ | ------------------------------------------------------------------------------------------------------ |
| Subscribe deadline | Send a `subscribe` message within **10 seconds** of opening the connection, or the server disconnects. |
| Channel limit      | **50 channel instances** per connection.                                                               |
| Compression        | `permessage-deflate` supported.                                                                        |
| Message format     | JSON, UTF-8.                                                                                           |

## Heartbeat

Send a ping every 30 seconds. The server disconnects after 60 seconds with no heartbeat.

```json
// Client → Server
{ "op": "ping" }

// Server → Client
{ "op": "pong", "time": 1719500000000 }
```

## Subscribing

```json
{
  "op": "subscribe",
  "args": [
    { "channel": "bbo", "symbol_id": 100001 },
    { "channel": "order", "address": "0xabc…def" }
  ]
}
```

```json
{ "op": "subscribe", "success": true, "args": [...] }
```

Unsubscribing is identical with `"op": "unsubscribe"`.

## Push Format

All channels share this envelope:

```json
{
  "channel": "<channel>",
  "symbol_id": "<symbol_id>",
  "type": "<type>",
  "ts": 1719500000000,
  "finality": "final",
  "data": { ... }
}
```

| Field       | Meaning                                                                                                                               |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `channel`   | Channel name.                                                                                                                         |
| `symbol_id` | Present for market-data channels. Omitted for Explorer / User.                                                                        |
| `type`      | Sub-type identifier. Used where a channel emits multiple shapes (e.g. `l2_book` emits `"snapshot"` and `"delta"`). Omitted otherwise. |
| `ts`        | Server push time, Unix milliseconds.                                                                                                  |
| `finality`  | Always `"final"` — data is block-finalized before being pushed (3-block finality, ≈ 150 ms).                                          |
| `data`      | Channel-specific payload.                                                                                                             |

## Push Timing

> **All** channels push after block finalization (3-block finality, \~150 ms). A channel only pushes when its data has actually changed — **empty blocks produce no push**.


---

# 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.lynxtrade.world/websocket/connection-and-subscription.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.
