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

133
Views
Unable to print property values of event.data object in Websocket?

I am trying to use Websocket for the first time but am not able to get the values of property of event object.

Here's my script

let socket = new WebSocket('wss://stream.binance.com:9443/ws/ethusdt@kline_1m')

let o = {
  "method": "SUBSCRIBE",
  "params": [
    "ethusdt@kline_1m"
  ],
  "id": 1
}

socket.send(JSON.stringify(o)) 

socket.addEventListener('message', (e)=>{let candle = e.data; console.log(candle['k'])})

e.data returns object like this :

{
  "e": "kline",     // Event type
  "k": {
    "o": "0.0010",  // Open price
    "c": "0.0020",  // Close price
    "h": "0.0025",  // High price
    "l": "0.0015",  // Low price
  }
}

However, my script always returns undefined.

How can I get those values?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just found that I need to use JSON.parse() to convert e.data into object.

So, it turns to this socket.addEventListener('message', (e)=>{let candle = JSON.parse(e.data); console.log(candle['k'])})

about 4 years ago · Juan Pablo Isaza Report
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!