binary-live-api
I´m trying to test the binary-live-api, using the code example of the github page, but I´m only getting error messages.
My code:
var ws = require('ws');
var LiveApi = require('binary-live-api').LiveApi;
var api = new LiveApi({ websocket: ws });
api.authorize('My token'');
api.getPortfolio();
api.events.on('portfolio', function(data) {
ping();
});
Error message of node:
(node:2756) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AuthorizationRequired: [ServerError] Please log in.
{
"portfolio": 1,
"req_id": 2
}
What should I do?
Thank you.
Comments
Is token you entered something like ffbf4454h3blghfug ?
I've tried many tokens, including the oauth ones. Do you think it's only a token problem? I can't remember if it was like that ( ffbf4454h3blghfug). I'll try again and send you a picture.
I've tried de API token and the oauth token at the API Playground and the response was ok on both. But when I've tested them on node.js, using the binary-live-api, I've got the same error message.
This is an async call which means the code does not wait for authorization automatically. You need to wait for
authorize
response before you request forportfolio
.One way is to listen for
authorize
event
like you did for the portfolio responselike this:
Another way is to use new javascript capability called promises which is more readable but may not be compatible with older browsers.
BTW, using binary-live-api you don't need to ping manually, the library will take care of that for you.