Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda