WebSocket API

Stream live energy prices from all providers over a persistent WebSocket connection. No authentication required.

Connection

Connect to wss://merx.exchange/ws to begin receiving price updates. The connection is public and does not require an API key.

Subscribing to Providers

By default you receive updates for all providers. To filter, send a subscribe message specifying which providers you want.

200Subscribe message
{ "subscribe": ["catfee", "itrx"] }

Message Format

Each message is a ProviderPrice object, identical in structure to the objects returned by GET /api/v1/prices. The server subscribes to the internal Redis prices:updated channel and forwards updates to connected clients.

200Price update message
{
  "provider": "catfee",
  "energy_prices": [
    { "duration_sec": 86400, "price_sun": 84, "min_amount": 32000 },
    { "duration_sec": 259200, "price_sun": 78, "min_amount": 32000 }
  ],
  "updated_at": "2026-03-29T12:00:01Z"
}

Heartbeat

The server sends a ping frame every 30 seconds. Clients must respond with a pong frame (handled automatically by most WebSocket libraries). Connections that fail to respond are cleaned up by the server.

Reconnection

Implement exponential backoff when reconnecting: 1 second, 2 seconds, 4 seconds, up to a maximum of 30 seconds. Reset the backoff timer after a successful connection.

INFO

WebSocket connections may be dropped during deployments. Always implement reconnection logic in production applications.

Code Examples

WebSocket client
const ws = new WebSocket('wss://merx.exchange/ws')

ws.addEventListener('open', () => {
  // Subscribe to specific providers
  ws.send(JSON.stringify({ subscribe: ['catfee', 'itrx'] }))
})

ws.addEventListener('message', (event) => {
  const price = JSON.parse(event.data)
  console.log(price.provider, price.energy_prices)
})

ws.addEventListener('close', () => {
  // Implement reconnection with backoff
  setTimeout(() => reconnect(), 1000)
})