ws.onmessage = (evt) => {
const msg = JSON.parse(evt.data);
// Handle different channel messages
switch (msg.cmd) {
case 'ticker':
console.log('Ticker update:', msg.data);
// { symbol: 'AAPL.US', last_price: '150.25', timestamp: 1703123456789 }
break;
case 'depth':
console.log('Depth update:', msg.data);
// { symbol: 'BTCUSDT', bids: [...], asks: [...], timestamp: 1703123456789 }
break;
case 'trade':
console.log('Trade update:', msg.data);
// { symbol: '700.HK', price: '350.20', quantity: '100', side: 'buy', timestamp: 1703123456789 }
break;
case 'pong':
console.log('Pong received:', msg.data);
// { timestamp: 1773336522965 }
break;
default:
console.log('Other message:', msg);
}
};