Skip to content

Update JavaScript example on https://docs.bitfinex.com/reference/ws-public-ticker #581

@manoelcampos

Description

@manoelcampos

Issue type

  • bug
  • missing functionality
  • performance
  • feature request
  • Example / Documentation

Brief description

The JS example available at the documentation site is designed to work with Node.js. However, if we make some little changes, it will also work out-of-the-box on the browser after we remove the require line:

-    const ws = require('ws')
+    const WebSocket = require('ws')

-    const w = new ws('wss://api-pub.bitfinex.com/ws/2')
+    const ws = new WebSocket('wss://api-pub.bitfinex.com/ws/2')
 
-    w.on('message', (msg) => console.log(msg))
+    ws.onmessage = (msg) => console.log(msg)
 
-    let msg = JSON.stringify({ 
+    const msg = JSON.stringify({ 
         event: 'subscribe', 
         channel: 'ticker', 
         symbol: 'tBTCUSD' 
     })
 
-    w.on('open', () => w.send(msg))
+    ws.onopen = () => ws.send(msg)
Additional Notes:

I couldn't find the mentioned documentation site here at GitHub, so that I could send a PR proposing the changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions