Overview

WebSocket connection management is fundamental to accessing Roxom’s real-time data streams. This section covers connection establishment, authentication, heartbeat management, and reconnection strategies.

Connection Types

Quick Start

Connection (API key authentication)

const timestamp = Date.now();
const signature = generateHMACSignature(apiSecret, timestamp.toString());

// Most WebSocket clients don't support custom headers directly; use your env's option if available.
// For Node/tungstenite-style clients you can set headers as below.
const ws = new WebSocket('wss://ws.roxom.com/ws', [], {
  headers: {
    'X-API-Key': apiKey
  }
});

ws.onopen = () => console.log('Connected');
ws.onmessage = (event) => console.log('Received:', JSON.parse(event.data));
The WebSocket server requires API key headers during the handshake:
  • X-API-Key
  • X-API-Timestamp (milliseconds)
  • X-API-Signature (HMAC of timestamp)

Connection Workflow

1

Environment Setup

Configure your environment variables and connection URLs for production or sandbox.
2

Establish Connection

Connect to the appropriate WebSocket endpoint with or without authentication headers.
3

Handle Connection Events

Implement event handlers for open, message, close, and error events.
4

Implement Heartbeat

Set up ping/pong mechanism to maintain connection health.
5

Add Reconnection Logic

Implement exponential backoff reconnection strategy for reliability.

Best Practices

Next Steps

After establishing a connection, you can: