binary-com / binary-live-api

JS library to consume Binary.com WebSocket API
https://developers.binary.com
MIT License
45 stars 74 forks source link

Error: unexpected server response (401) #113

Open frxncisjoseph opened 7 years ago

frxncisjoseph commented 7 years ago

Hello,

I'm experiencing a very strange issue with the binary-live-api library.

I attempted a test run using the following example code:

var ws = require('ws');
var LiveApi = require('binary-live-api').LiveApi;

var api = new LiveApi({ websocket: ws });
api.authorize('my token is here');
api.getPortfolio();
api.events.on('portfolio', function(data) {
    onsole.log(data);
});

Which resulted in this error:

Error: unexpected server response (401)
    at ClientRequest.options._req.on (/Users/FrancisJoseph/node_modules/ws/lib/WebSocket.js:650:26)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:472:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:99:23)
    at TLSSocket.socketOnData (_http_client.js:361:20)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at TLSSocket.Readable.push (_stream_readable.js:134:10)

Any ideas?

yogeshwar607 commented 7 years ago

Same issue , any help ? @frxncisjoseph resolved ?

frxncisjoseph commented 7 years ago

@yogeshwar607 Not resolved and no response from the repository creators nor anyone else...

ghost commented 7 years ago

Same issue here

ghost commented 7 years ago

I looked into this and found the recent requirement for an app_id was causing issues. You'll need a valid app_id from: https://developers.binary.com/applications/

It can be fixed by changing: var api = new LiveApi({websocket: ws}); to: var api = new LiveApi({websocket: ws, appId: 0000}); Replace '0000' with your app_id.

ghost commented 7 years ago

Thanks Luke, I'd just realised that they made this app_id request mandatory a few weeks ago. Nice one :)