Roxom.com

WebSocket Overview

Copy page

Learn how Roxom's WebSocket API delivers real-time market data and account updates for trading apps.

Overview

The Roxom WebSocket API provides real-time access to market data and account updates with minimal latency. Use it to build trading applications, monitor portfolios, and implement algorithmic trading strategies.

What you can access

Market Data Streams

Authentication required for market data streams:

  • Level 1 Quotes: Best bid and ask prices and quantities
  • Trade Executions: Real-time trade data with volume statistics
  • Order Book Depth: Complete order book with multiple price levels
  • Ticker Data: Real-time price and market statistics including funding rates and open interest
Private Account Data

Authentication required for private account streams:

  • Order Updates: Real-time order status changes and fills
  • Balance Changes: Account balance updates from trades and transfers
  • Position Updates: Position changes and PnL updates

Connection URLs

Production
wss://ws.roxom.com/ws
Sandbox
wss://ws.roxom.io/ws

Supported trading pairs

Current supported symbols for market data streams:

SymbolDescriptionBase AssetQuote Asset
GOLD-BTCGold to BitcoinPAXBTC
USDT-BTCTether to BitcoinUSDTBTC

Message format

All WebSocket messages use JSON format with a consistent structure:

Client to server messages

{
  "op": "subscribe|unsubscribe",
  "args": [
    {
      "channel": "channelName",
      "symbol": "tradingPair"
    }
  ]
}

Server to client messages

{
  "topic": "channel.symbol",
  "type": "snapshot|delta",
  "createdTime": 1640995200000000000,
  "data": {
    // Channel-specific data
  }
}

Supported channels

ChannelDescriptionSymbol RequiredAuthentication
level1Best bid and ask prices and quantitiesYesYes
tradeReal-time trade executionsYesYes
depthOrder book depth (snapshot + deltas)YesYes
tickerReal-time price and market statisticsYesYes
ordersOrder updates for authenticated userNoYes
balanceBalance updates for authenticated userNoYes
positionsPosition updates for authenticated userNoYes

Connection lifecycle

  1. Establish Authenticated Connection

    All WebSocket connections require authentication using API key headers during the connection handshake.

    // Generate RSA signature for the payload 'GET:/ws'
    const signature = generateRSASignature(privateKey, 'GET:/ws');
    
    const ws = new WebSocket('wss://ws.roxom.com/ws', [], {
      headers: {
        'X-API-Key': 'your_api_key',
        'X-API-Signature': signature
      }
    });
  2. Handle Connection Events

    Implement proper event handlers for connection management.

    ws.onopen = () => {
      console.log('✅ WebSocket connected and authenticated');
    };
    
    ws.onerror = (error) => {
      console.error('❌ WebSocket error:', error);
    };
    
    ws.onclose = (event) => {
      console.log('🔌 WebSocket closed:', event.code, event.reason);
      // Implement reconnection logic
    };
  3. Subscribe to Channels

    Send subscription messages for the data streams you need.

    {
      "op": "subscribe",
      "args": [
        { "channel": "level1", "symbol": "GOLD-BTC" },
        { "channel": "depth", "symbol": "USDT-BTC" },
        { "channel": "orders" }
      ]
    }
  4. Handle Messages

    Process incoming real-time data and maintain connection status.

    ws.onmessage = function(event) {
      const data = JSON.parse(event.data);
      console.log('Received:', data);
    };
  5. Maintain Connection

    Implement ping/pong and reconnection logic for reliability.

Key features

Low Latency

Sub-millisecond message delivery for time-sensitive trading applications

Multiple Streams

Subscribe to multiple symbols and channels simultaneously

Reliable Delivery

Built-in heartbeat and reconnection mechanisms

Efficient Updates

Delta updates minimize bandwidth usage for order book streams

Best practices

Connection Management
  • Single Connection: Use one connection per application when possible
  • Reconnection Logic: Implement exponential backoff for reconnections
  • Heartbeat Monitoring: Send ping frames every 30 seconds
  • Resource Cleanup: Properly close connections when shutting down
Subscription Management
  • Selective Subscriptions: Only subscribe to data you actually need
  • Unsubscribe Unused: Remove subscriptions you no longer need
  • Batch Operations: Subscribe to multiple channels in single message
  • Symbol Validation: Verify symbol names before subscribing
Error Handling
  • Graceful Degradation: Handle connection drops gracefully
  • Error Parsing: Always validate JSON before parsing
  • Retry Logic: Implement smart retry mechanisms
  • Logging: Log connection events for debugging

Getting started

Last modified on