Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

110
Views
javascript websocket error, I want to get event.data in global scope

I want extract real time data from binance websocket. but result error.

let socket = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@trade");

        socket.onmessage = function(event){
        let current_price = JSON.parse(event.data);
        
        // console.log(current_price); :is okay!

        return current_price;
        }

let Data = socket.onmessage();

console.log(Data); :not okay..

even.data in function scope has no error,
but event.data not in function scope has this error.
Uncaught TypeError: Cannot read properties of undefined (reading 'data')

I want to get even.data in global scope.

plz help.

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs