Giter Club home page Giter Club logo

Comments (2)

bennycode avatar bennycode commented on July 17, 2024

The "coinbase-pro-node" library was developed to run in a Node.js environment. However, it is possible to use the package in a browser environment (where Vue.js frontend apps are running) but you have to be aware of some consequences:

  • REST calls are likely to be blocked by the browser's CORS policy, so you have to start your browser with disabled web security or use a proxy (i.e. webpack's dev server proxy) to communicate with Coinbase Pro's backend.
  • WebSocket connections are established using the "ws" package (Node.js), but the browser comes with a native WebSocket implementation, so the constructor passed to ReconnectingWebSocket must be changed (Example).

Are you just having problems with establishing a WebSocket connection or do REST calls also fail for you?

from coinbase-pro-node.

caiqueacct avatar caiqueacct commented on July 17, 2024

Thank you for the update. I was able to get this working using the link that you sent.

async coinbaseRealtime() {
this.ws = new ReconnectingWebSocket(
'wss://ws-feed.pro.coinbase.com',
[],
{
key: '',
passphrase: '',
signature: '',
timestamp: Date.now() / 1000
}
)

  this.ws.addEventListener('error', (e) => {
    console.debug('error', e)
  })

  this.ws.addEventListener('open', () => {
    console.debug('Connection open')
    const subscribe = {
      "type": 'subscribe',
      "channels": [
        {
          "name": 'ticker',
          "product_ids": ['BTC-USD', 'ETH-USD', 'LTC-USD']
        }
      ]
    }
    this.ws.send(JSON.stringify(subscribe))
  })

  this.ws.addEventListener('message', (data) => {
    console.debug('Received message', data)
  })

}

from coinbase-pro-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.