Market Data
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
Best bid and ask prices and quantities in real-time
Trade ExecutionsReal-time trade data with volume statistics
Order Book DepthComplete order book with multiple price levels
Ticker DataReal-time ticker data and price statistics
Stream types overview
| Channel | Description | Update Frequency | Authentication |
|---|---|---|---|
level1 | Best bid and ask quotes | Real-time | Required |
trade | Trade executions with volume stats | Per trade | Required |
depth | Full order book depth | Real-time | Required |
ticker | Comprehensive ticker data including funding rates, open interest, and mark prices | Real-time | Required |
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
| Symbol | Description | Base Asset | Quote Asset |
|---|---|---|---|
GOLD-BTC | Gold to Bitcoin | GOLD | BTC |
USDT-BTC | Tether to Bitcoin | USDT | BTC |
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
- Learn about Level 1 Quotes implementation details
- Explore Trade Executions for real-time trade data
- Review Order Book Depth for full market depth
- Set up Connection Management for reliable connectivity
- Explore Account Updates for private data streams
Last modified on