coinbase / coinbase-pro-node

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

websocket doesnot return anything #216

Closed Lifestohack closed 6 years ago

Lifestohack commented 6 years ago

Description: Websocket does not return anything.

 const server = testserver(++port, () => {
const websocket = new Gdax.WebsocketClient(this.cryptocurrency,
                                            'ws://localhost:' + port,
                                            {
                                                      key: this.key,
                                                      secret: this.secret,
                                                      passphrase: this.passphrase,
                                            },
                                            { channels: ['ticker'] },
                                          );
  server.on('connection', socket => {
   console.log(socket);
      socket.on('message', data => {
      const msg = JSON.parse(data);
      console.log(msg);
      });
            socket.on('error', err => {
            console.log(err);
            });
});
 });

Am I doing something wrong? I double checked it. If I run this from cmd line the cursor just blinks and nothing happen

rmm5t commented 6 years ago

Why are you connecting to localhost? Are you running a local proxy, or was this an oversight?

Edit: Oh. It looks like you copied code from the tests directory. Was that intentional?

Lifestohack commented 6 years ago

@rmm5t Hi Ryan, yeah that was from test folder. I also copied the websoketserver file also. The cursur just blinks and nothing happens. Then I tried this:

const websocket = new Gdax.WebsocketClient(this.cryptocurrency,
                                            'https://api-public.sandbox.gdax.com',
                                            {
                                                      key: this.key,
                                                      secret: this.secret,
                                                      passphrase: this.passphrase,
                                            },
                                            { channels: ['ticker'] },
                                          );

      websocket.on('message', msg => {
      console.log(msg);
      });
  websocket.on('error', err => {
      console.log(err);
      });

It gives me unexpected server error(400).

rmm5t commented 6 years ago

It gives me unexpected server error(400).

More information is necessary.

Lifestohack commented 6 years ago

I replaced 'https://api-public.sandbox.gdax.com', with 'wss://ws-feed.gdax.com' and it started working. Thanks.