Overview

Access real-time market data through WebSocket streams. All WebSocket connections require authentication using API key headers during the connection handshake.

Available Streams

Stream Types Overview

ChannelDescriptionUpdate FrequencyAuthentication
level1Best bid/ask quotesReal-timeRequired
tradeTrade executions with volume statsPer tradeRequired
depthFull order book depthReal-timeRequired
tickerReal-time ticker statistics (includes open interest where available)Real-timeRequired

Quick Subscribe

Multiple Streams Example

{
  "op": "subscribe",
  "args": [
    { "channel": "level1", "symbol": "US500-BTC" },
    { "channel": "trade", "symbol": "GOLD-BTC" },
    { "channel": "depth", "symbol": "OIL-BTC" }
  ]
}

JavaScript Implementation

// Create authenticated WebSocket connection (see Connection docs)
const ws = new WebSocket('wss://ws.roxom.com/ws', [], {
  headers: {
    'X-API-KEY': 'your-api-key',
    'X-API-TIMESTAMP': Date.now().toString(),
    'X-API-SIGN': 'your-hmac-signature'
  }
});

ws.onopen = function() {
  // Subscribe to multiple market data streams
  ws.send(JSON.stringify({
    op: 'subscribe',
    args: [
      { channel: 'level1', symbol: 'US500-BTC' },
      { channel: 'trade', symbol: 'GOLD-BTC' },
      { channel: 'depth', symbol: 'OIL-BTC' }
    ]
  }));
};

ws.onmessage = function(event) {
  const data = JSON.parse(event.data);
  
  // Handle subscription confirmations
  if (data.event === 'subscribe') {
    console.log('Subscribed to:', data.arg.channel, data.arg.instId);
    return;
  }
  
  // Handle market data events
    if (data.topic) {
      const [channel, symbol] = data.topic.split('.');
      
      switch (channel) {
        case 'level1':
          handleLevel1Update(symbol, data.data);
          break;
        case 'trade':
          handleTradeUpdate(symbol, data.data);
          break;
        case 'depth':
          handleDepthUpdate(symbol, data.data);
          break;
      }
    }
  };

function handleLevel1Update(symbol, data) {
  console.log(`${symbol} Level 1 - Bid: ${data.bid[0]} Ask: ${data.ask[0]}`);
}

function handleTradeUpdate(symbol, data) {
  console.log(`${symbol} Trade - ${data.takerSide} ${data.vwap} Vol: ${data.volume}`);
}

function handleDepthUpdate(symbol, data) {
  console.log(`${symbol} Depth - ${data.type} update with ${data.bid.length} bids, ${data.ask.length} asks`);
}

Supported Trading Pairs

SymbolDescriptionBase AssetQuote Asset
US500-BTCS&P 500 Index to BitcoinUS500BTC
GOLD-BTCGold to BitcoinGOLDBTC
OIL-BTCOil to BitcoinOILBTC

Message Format

All market data messages follow a consistent structure:
{
  "topic": "channel.symbol",
  "type": "snapshot|delta|update",
  "createdTime": 1640995200000000000,
  "data": {
    // Channel-specific data
  }
}

Subscription Management

Subscribe to Streams

{
  "op": "subscribe",
  "args": [
    { "channel": "level1", "symbol": "US500-BTC" }
  ]
}

Unsubscribe from Streams

{
  "op": "unsubscribe",
  "args": [
      { "channel": "trade", "symbol": "GOLD-BTC" }
  ]
}

Best Practices

Error Handling

Common market data stream errors and solutions:

Next Steps