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.