Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
How Do I handle receiving multiple WebSocket onopen & onmessage Using JavaScript?

I Am New to Coding and Learning to start small Projects to help me improve and learn-

I wanted to get Different WebSocket feed simultaneously in the same Script- response for both granularity for 300 & 900 at the same time; below is the actual code for a single request

const WebSocket = require('ws');
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1089');


ws.onopen = function(evt) {
   
    ws.send(JSON.stringify(
    {ticks_history: "R_25",
     subscribe: 1,
     adjust_start_time: 1,
     count: 1,
     end: "latest",
     granularity: 300,
     start: 1,
     style: "candles"}
     
    ));

};

ws.onmessage = function(msg) {
   var data = JSON.parse(msg.data);
   console.log('ticks update: %o', data.tick.quote);

};

Where by I can get different granularity response of same feed at the same time, although I have been able to get this independently but would love to be able to get them all from the same script!

Below is my script

const WebSocket = require('ws');
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1089');


ws.onopen = function(evt) {
   
    ws.send(JSON.stringify(
    {ticks_history: "R_25",
     subscribe: 1,
     adjust_start_time: 1,
     count: 1,
     end: "latest",
     granularity: 900,
     start: 1,
     style: "candles"}, 

//here is where i added the additional request for 900 time frame

     {ticks_history: "R_25",
     subscribe: 1,
     adjust_start_time: 1,
     count: 1,
     end: "latest",
     granularity: 300,
     start: 1,
     style: "candles"}
     
    ));

};

ws.onmessage = function(msg) {
   var data = JSON.parse(msg.data);
   console.log('ticks update: %o', data);

};

from the above script, I only get a data feed from only the second request -900

How do I write this that will allow me to get both data responses same time?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda