const WebSocket = require('ws');

const ws = new WebSocket('ws://localhost:3000/ws');

ws.on('open', () => {
  console.log('✓ Connected to WebSocket');
  ws.send(JSON.stringify({ type: 'subscribe', data: { channel: 'price_updates' } }));
});

ws.on('message', (data) => {
  console.log('✓ Received:', data.toString());
});

ws.on('close', (code, reason) => {
  console.log(`✗ Connection closed: ${code} - ${reason}`);
});

ws.on('error', (error) => {
  console.error('✗ WebSocket error:', error.message);
});

setTimeout(() => {
  console.log('Closing connection...');
  ws.close();
  process.exit(0);
}, 5000);
