Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
¿Cómo manejo la recepción de múltiples WebSocket onopen y onmessage usando JavaScript?

Soy nuevo en la codificación y el aprendizaje para comenzar pequeños proyectos que me ayuden a mejorar y aprender.

Quería obtener diferentes fuentes de WebSocket simultáneamente en la misma respuesta de secuencia de comandos para la granularidad de 300 y 900 al mismo tiempo; a continuación se muestra el código real para una sola solicitud

 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); };

Donde puedo obtener una respuesta de granularidad diferente del mismo feed al mismo tiempo, aunque he podido obtener esto de forma independiente, ¡pero me encantaría poder obtenerlos todos del mismo script!

A continuación se muestra mi guión

 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); };

del script anterior, solo obtengo una fuente de datos solo de la segunda solicitud -900

¿Cómo escribo esto que me permitirá obtener ambas respuestas de datos al mismo tiempo?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!