peterszombati / xapi-node

xStation5 Trading API for NodeJS/JS
https://peterszombati.github.io/xapi-node/
Other
58 stars 19 forks source link

getCandles listener never gets triggered #16

Closed solarfrantz closed 3 years ago

solarfrantz commented 3 years ago

I've tried to get the realtime candles, even waited more the one minute as the official docs says and apparently the listener never gets called, see the code from below:

const x = new XAPI.default({
    accountId: <MY-ACCOUNT-ID>,
    password: <MY-PASSWORD>,
    type: 'demo' // or demo
});

x.connect();

x.onReady(async () => {
    console.log('Connection is ready');

    x.Stream.listen.getCandles((data) => {
        // THIS IS NEVER REACHED
        console.log("GOT DATA", data);
    });

    x.Stream.subscribe.getCandles('BITCOIN')
        .catch(() => { console.error('subscribe for BITCOIN failed')});

})

Am I doing something wrong ?

PS: getTickPrices works as expected

peterszombati commented 3 years ago

Hi @solarfrantz I found the bug, its caused by xOpenHub server logic.

for quick fix you have to do this request before subscribe for candles

x.getPriceHistory({
  symbol: 'BITCOIN',
  period: PERIOD_FIELD.PERIOD_M1,
  ticks: -1
})

I close this ticket and create another one

peterszombati commented 3 years ago

I created a new issue related to this: https://github.com/peterszombati/xapi-node/issues/17

solarfrantz commented 3 years ago

That's very odd, have you tried also submitting a bug on their API's, maybe they'll fix it and we won't have to do this ugly workaround ?