Heartbeat & Keep-Alive

60-second idle timeout, ping/pong, keepalive patterns.

The server enforces a 60-second idle timeout. If no data flows through your connection for 60 seconds, it will be automatically closed.

Ping / Pong

Send periodic pings to keep your connection alive:

Ping

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

Pong (server response)

{"channel": "pong"}
{"channel": "pong"}
{"channel": "pong"}

Send a ping every 30 seconds to stay well within the timeout window:

JavaScript

// Send ping every 30 seconds
const pingInterval = setInterval(() => {
  if (ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({ method: "ping" }));
  }
}, 30000);

// Clean up on close
ws.onclose = () => clearInterval(pingInterval);
// Send ping every 30 seconds
const pingInterval = setInterval(() => {
  if (ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({ method: "ping" }));
  }
}, 30000);

// Clean up on close
ws.onclose = () => clearInterval(pingInterval);
// Send ping every 30 seconds
const pingInterval = setInterval(() => {
  if (ws.readyState === WebSocket.OPEN) {
    ws.send(JSON.stringify({ method: "ping" }));
  }
}, 30000);

// Clean up on close
ws.onclose = () => clearInterval(pingInterval);

Python

import asyncio

async def keepalive(ws):
    while True:
        await ws.send('{"method": "ping"}')
        await asyncio.sleep(30)
import asyncio

async def keepalive(ws):
    while True:
        await ws.send('{"method": "ping"}')
        await asyncio.sleep(30)
import asyncio

async def keepalive(ws):
    while True:
        await ws.send('{"method": "ping"}')
        await asyncio.sleep(30)

Info

If you are subscribed to high-frequency channels like raw_book_diffs, the constant data flow acts as an implicit keepalive. Explicit pings are only needed for quiet channels.

Home

/

Introduction

On this page

Real-Time Streams

/

Heartbeat & Keep-Alive

Real-Time Streams

/

Heartbeat & Keep-Alive