# Websocket

Mainnet websocket URL: <wss://ws.pacifica.fi/ws>\
Testnet websocket URL: <wss://test-ws.pacifica.fi/ws>

The API service provides a universal endpoint for websocket streams. The subscribed data will be streamed in the corresponding channel after the connection is established.

### Subscription Message

```
{
    "method": "subscribe",
    "params": { ... }
}
```

### Unsubscription Message

```
{
    "method": "unsubscribe",
    "params": { ... }
}
```

### Heartbeat and Timeout

A webscoket connection will be closed if no message is sent for the past 60 seconds, or the connection has been alive for 24 hours.

To keep the connection alive without messages in 60 seconds, we can send a heartbeat message

```
{
    "method": "ping"
}
```

and alive connection will respond with

```
{
    "channel": "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://pacifica.gitbook.io/docs/api-documentation/api/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.
