Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 5 tasks
manoelcampos opened this issue Sep 13, 2022 · 0 comments
Open
1 of 5 tasks

Comments

@manoelcampos
Copy link

manoelcampos commented Sep 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant