Roxom.com

Market Data

Copy page

Subscribe to real-time level 1 quotes, trades, order book depth, and ticker data via WebSocket.

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 and ask quotesReal-timeRequired
tradeTrade executions with volume statsPer tradeRequired
depthFull order book depthReal-timeRequired
tickerComprehensive ticker data including funding rates, open interest, and mark pricesReal-timeRequired

Quick subscribe

Multiple streams example

{
  "op": "subscribe",
  "args": [
    { "channel": "level1", "symbol": "GOLD-BTC" },
    { "channel": "trade", "symbol": "USDT-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-Signature': 'base64-encoded-rsa-signature'
  }
});

ws.onopen = function() {
  // Subscribe to multiple market data streams
  ws.send(JSON.stringify({
    op: 'subscribe',
    args: [
      { channel: 'level1', symbol: 'USDT-BTC' },
      { channel: 'trade', symbol: 'GOLD-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
GOLD-BTCGold to BitcoinGOLDBTC
USDT-BTCTether to BitcoinUSDTBTC

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": "GOLD-BTC" }
  ]
}

Unsubscribe from streams

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

Best practices

Subscription Strategy
  • Subscribe only to data you actually need
  • Use batch subscriptions for multiple symbols
  • Unsubscribe from unused streams to reduce bandwidth
  • Validate symbol names before subscribing
Data Processing
  • Handle snapshot vs delta updates appropriately
  • Implement proper order book reconstruction for depth streams
  • Buffer high-frequency updates for UI rendering
  • Maintain local state for efficient processing
Performance Optimization
  • Process messages asynchronously
  • Use efficient data structures for order books
  • Implement proper memory management
  • Monitor bandwidth usage and adjust subscriptions

Error handling

Common market data stream errors and solutions:

Invalid Symbol

Error: Subscription rejected due to invalid trading pair

Solution: Verify symbol format matches supported trading pairs exactly

Rate Limiting

Error: Too many subscription requests

Solution: Batch multiple subscriptions into single request

Connection Issues

Error: Message delivery interruption

Solution: Implement reconnection logic and state recovery

Next steps

Last modified on