Heartbeat Mechanism
The NBX WebSocket API uses a ping/pong heartbeat system to ensure connection health.
Server Ping
The server will periodically send a ping message:
{
"event": "ping",
"data": {
"message": "ping"
}
}
Client Response
Your client must respond with a pong message:
{
"event": "pong",
"data": {
"message": "pong"
}
}
If your client fails to respond to ping messages within 300 seconds, the server will terminate the connection.
Example Implementation
import WebSocket from 'ws';
const ws = new WebSocket('wss://api.novig.us/tape', {
headers: {
'Authorization': `Bearer ${ACCESS_TOKEN}`
}
});
ws.on('message', (data) => {
const message = JSON.parse(data.toString());
// Handle ping/pong
if (message.event === 'ping') {
ws.send(JSON.stringify({
event: 'pong',
data: { message: 'pong' }
}));
}
// Handle other messages...
});