Skip to main content

Heartbeat Mechanism

The NBX WebSocket API uses a client-initiated ping/pong heartbeat to keep connections alive. The server does not send pings on its own — it only responds to pings sent by the client. The connection is dropped by the upstream load balancer after 300 seconds of no traffic in either direction. Any message — a market update from the server, a subscribe from you, a ping, or a pong — resets that idle timer. In practice this means you only need to send a ping during quiet periods; while the server is actively pushing data to you, the connection stays alive on its own. Track the timestamp of the last message you received. If that timestamp is older than some threshold (e.g. 30 seconds), send a ping. This avoids unnecessary pings during active periods and guarantees the connection stays warm during quiet ones.

Client Ping

Send a ping message after a period of no inbound traffic:

Server Response

The server replies with a pong message:
The connection is dropped after 300 seconds with no messages flowing in either direction. Any inbound or outbound message resets the idle timer.

Example Implementation