# Websockets

## WebSockets

The platform provides two WebSocket endpoints for real-time data:

**Base URL**: `wss://v2.api.dexodus.finance`

### WS /ws-prices

Real-time price and market status updates.

#### Subscription Message

```json
{
  "action": "subscribe",
  "markets": ["BTC", "ETH", "SOL"]
}
```

**Parameters:**

* `action`: `"subscribe"` or `"unsubscribe"`
* `markets`: Array of markets you want to subscribe to. If empty, subscribes to all available markets.

#### Initial Snapshot Message

Server automatically sends initial data snapshot with current data for all markets.

```json
{
  "type": "initial_data_snapshot",
  "data": {
    "BTC": {
      "perpetualPrice": 45000.50,
      "indexPrice": 45010.25,
      "currentDate": "2024-01-15T10:30:00.000Z",
      "price24hAgo": 44500.00,
      "date24hAgo": "2024-01-14T10:30:00.000Z",
      "marketStatus": "Open"
    },
    "ETH": {
      "perpetualPrice": 2500.75,
      "indexPrice": 2502.50,
      "currentDate": "2024-01-15T10:30:00.000Z",
      "price24hAgo": 2450.00,
      "date24hAgo": "2024-01-14T10:30:00.000Z",
      "marketStatus": "Open"
    }
    // ... all other markets
  }
}
```

#### Real-time Update Message

Server sends price status update messages for real-time updates automatically when prices change.

```json
{
  "type": "price_status_update",
  "symbol": "BTC",
  "perpetualPrice": 45025.75,
  "indexPrice": 45030.00,
  "marketStatus": "Open",
  "timestamp": "2024-01-15T10:31:00.000Z"
}
```

### WS /ws

Real-time candlestick data.

#### Subscription Message

```json
{
  "action": "subscribe",
  "symbol": "BTC",
  "resolution": "1"
}
```

**Parameters:**

* `action`: `"subscribe"` or `"unsubscribe"`
* `symbol`: Symbol name
* `resolution`: Value is in minutes:
  * `"1"` - 1 minute candle
  * `"5"` - 5 minutes candle
  * `"240"` - 4 hours candle
  * `"1D"` - 1 day candle (exception)

#### Response Message

```json
{
  "symbol": "BTC",
  "resolution": "1m",
  "candle": {
    "time": 1234567890000,
    "open": 50000.0,
    "high": 50100.0,
    "low": 49900.0,
    "close": 50050.0
  }
}
```

**Candle Update Behavior:**

* All updates have the same `time` (e.g., `1759939376000`) for the same candle period
* The `close` price is constantly updating (represents the current price)
* The `high` and `low` update as new highs/lows are hit
* The `open` stays the same (price when the candle period started)


---

# 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.dexodus.finance/trading-api/websockets.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.
