coinbase / coinbase-pro-node

DEPRECATED — The official Node.js library for Coinbase Pro
Apache License 2.0
844 stars 316 forks source link

Subscribing to ticker doenst work #353

Closed BennyAlex closed 5 years ago

BennyAlex commented 5 years ago

Hello, I try to subscribe to the ticker channel with the Websocketclient, but I just get something like that:

{ type: 'received',
  order_id: '0be8904a-e661-4f3f-b1d1-7818b0c2229c',
  order_type: 'limit',
  size: '0.74810613',
  price: '3394.98000000',
  side: 'sell',
  client_oid: 'ae1c0a0e-0d70-83b7-a7e2-e0d3d1002000',
  product_id: 'BTC-USD',
  sequence: 7516646171,
  time: '2018-12-08T12:08:47.686000Z' }
{ type: 'open',
  side: 'sell',
  price: '3394.98000000',
  order_id: '0be8904a-e661-4f3f-b1d1-7818b0c2229c',
  remaining_size: '0.74810613',
  product_id: 'BTC-USD',
  sequence: 7516646172,
  time: '2018-12-08T12:08:47.686000Z' }
{ type: 'heartbeat',
  last_trade_id: 55612873,
  product_id: 'BTC-USD',
  sequence: 7516646172,
  time: '2018-12-08T12:08:47.713000Z' }

My code:

const websocket = new Gdax.WebsocketClient({
    "type": "subscribe",
    "channels": [
        {
            "name": "ticker",
            "product_ids": [
                "ETH-BTC"
            ]
        },
    ]});

websocket.on('message', data => {
  console.log(data)
});
vansergen commented 5 years ago

According to README file your code should be like this

const websocket = new Gdax.WebsocketClient(
  ['ETH-BTC'],
  'wss://ws-feed.pro.coinbase.com',
  null,
  { channels: ['ticker'] }
);
fb55 commented 5 years ago

Thanks @vansergen!