Chart KLines

Chart WebSocket API

Real-time kline (candlestick) data streaming via WebSocket.

Connection

ws://back.dmex.app/ws/chart

Message Format

All messages use JSON with the following structure:

{
  "type": "message_type",
  "data": { ... }
}

Client → Server Messages

Subscribe to Kline Stream

Subscribe to real-time candlestick updates for a symbol/interval pair.

{
  "type": "subscribeKlineStream",
  "data": {
    "symbol": "BTCUSDT",
    "interval": "1m"
  }
}

Parameters:

  • symbol - Trading pair (e.g., BTCUSDT, ETHUSDT)

  • interval - Candle interval (e.g., 1m, 5m, 15m, 1h, 4h, 1d)

Unsubscribe from Kline Stream

Ping

Keep connection alive with application-level ping.

Server → Client Messages

Subscription Confirmed

Sent after successful subscription.

Kline Stream Update

Real-time candle data pushed to subscribed clients.

Candle fields (k):

Field
Description

t

Candle open time (Unix ms)

o

Open price

h

High price

l

Low price

c

Close price

v

Volume

x

Is candle closed

Pong

Response to client ping.

Example Usage (JavaScript)

Connection Management

  • Ping/Pong: Server sends WebSocket ping frames every 54 seconds

  • Read timeout: 60 seconds (reset on pong)

  • Connection cleanup: Stale connections removed after 120 seconds of inactivity

  • Throttling: Updates are throttled to max 1 broadcast per 300ms per symbol to prevent flooding

Multiple Subscriptions

You can subscribe to multiple symbol/interval pairs on a single connection:

Notes

  • Symbol names are case-insensitive (internally converted to lowercase)

  • Subscription keys are formatted as {symbol}_{interval} (e.g., btcusdt_1m)

  • The stream field in updates matches this subscription key format

Last updated