reCluster
  • Welcome
    • reCluster
    • Registration
    • Frequently Asked Questions
    • Roadmap
  • Features
    • Midprice
    • Tickers
    • Trades
    • OHLC
    • Volume Weighted Average Price
  • Integration
    • General Information
    • Python
    • Node.js
    • Golang
Powered by GitBook
On this page
  1. Integration

Node.js

Connect with Node.js

Prerequisites

  • Make sure you have Node.js installed.

  • Install the ws library: npm install ws

const WebSocket = require('ws');

const ws = new WebSocket('wss://ws.recluster.io/ws?password=example');

ws.on('open', () => {
  console.log('Connected to reCluster!');

  ws.send(JSON.stringify({
    topic: "orderbook",
    symbol: "BTCUSDT",
    action: "subscribe",
  }));
});

ws.on('message', (data) => {
  const messageString = data.toString();
  try {
    const json = JSON.parse(messageString);
    console.log('Data:', json);
  } catch (err) {
    console.error('Failed to parse JSON:', err, 'Raw data:', messageString);
  }
});

ws.on('pong', () => {
  console.log('Received pong from server');
});

ws.on('close', () => {
  console.log('WS connection closed');
});

ws.on('error', (err) => {
  console.error('WS error:', err);
});

PreviousPythonNextGolang

Last updated 3 months ago