# WebSocket Streams

* The base URL for all WSS interfaces listed in this document is: `wss://ws.dotswap.app`
  * The testnet base URL is: `wss://test-api-proxy.ddpurse.com:28910`
* All streams can be accessed directly or as part of combined streams.
* Direct access URL format: `/ws/`
* Combined streams URL format: `/stream?streams=,,`
* When subscribing to combined streams, event payloads are wrapped in this format: `{"stream":"","data":}`
* Each connection to `ws.dotswap.app` has a validity period of no more than 24 hours. Please handle reconnection properly.
* All time and timestamp related fields use milliseconds as the default unit.

## Ticker by Symbol (Single Trading Pair)

**Stream Name**: @trade

```javascript
// Subscribe to DOTSWAP•DOTSWAP/BTC ticker

const wsDSBTC = new WebSocket("wss://ws.dotswap.app/ws/DOTSWAP•DOTSWAP/BTC@trade");

wsDSBTC.onmessage = (event) => {
    const data = JSON.parse(event.data);
    console.log("DOTSWAP•DOTSWAP/BTC ticker:", data);
};
```

**Payload:**

```json
{
    "e": "trade", // Event type
    "E": 1763975983770, // Event time
    "s": "DOTSWAP•DOTSWAP/BTC", // Trading pair
    "p": "918.209", // Trade price
    "q": "1000", // Trade quantity
    "T": 1763975975000 // Trade time
}
```

## Ticker by Symbol (Multiple Trading Pairs)

**Stream Name**: @trade

```javascript
// Subscribe to DOTSWAP•DOTSWAP/BTC and DOG•GO•TO•THE•MOON/BTC tickers at once

const ws = new WebSocket(
"wss://ws.dotswap.app/stream?streams=DOTSWAP•DOTSWAP/BTC@trade,DOG•GO•TO•THE•MOON/BTC@trade"
);

ws.onmessage = (event) => {
    const message = JSON.parse(event.data);
    console.log("Received data:", message.stream, message.data);
};
```

**Payload:**

```json
{
"stream": "DOTSWAP•DOTSWAP/BTC@trade",
"data": {
  "e": "trade", // Event type
  "E": 1763975983770, // Event time
  "s": "DOTSWAP•DOTSWAP/BTC", // Trading pair
  "p": "918.209", // Trade price
  "q": "1000", // Trade quantity
  "T": 1763975975000 // Trade time
 }
}

```


---

# 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.on.nexus/dotswap/developers/market-data-and-feeds/websocket-streams.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.
