peterszombati / xapi-node

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

Stream commands not working in demo #13

Closed CamiloManrique closed 3 years ago

CamiloManrique commented 3 years ago

I'm not sure if there are restrictions with the stream commands in demo accounts, but I'm unable to make it work. This is my code:

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.getTickPrices((data) => {
        console.log(data.symbol + ': ' + data.ask + ' | ' + data.askVolume + ' volume | ' + data.level + ' level' );
    });

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

    const r = await x.Socket.send.getSymbol('EURUSD');
    console.log('response');
    console.log(r.returnData);
})

And the output is this:

Connection is ready
response
{
  symbol: 'EURUSD',
  currency: 'EUR',
  categoryName: 'FX',
  currencyProfit: 'USD',
  quoteId: 5,
  quoteIdCross: 4,
  marginMode: 101,
  profitMode: 5,
  pipsPrecision: 4,
  contractSize: 100000,
  exemode: 1,
  time: 1615582799825,
  expiration: null,
  stopsLevel: 0,
  precision: 5,
  swapType: 1,
  stepRuleId: 5,
  type: 971,
  instantMaxVolume: 2147483647,
  groupName: 'Major',
  description: 'Euro to American Dollar',
  longOnly: false,
  trailingEnabled: true,
  marginHedgedStrong: false,
  swapEnable: true,
  percentage: 100,
  bid: 1.19602,
  ask: 1.1961,
  high: 1.19881,
  low: 1.19096,
  lotMin: 0.01,
  lotMax: 100,
  lotStep: 0.01,
  tickSize: 0.00001,
  tickValue: 1,
  swapLong: -5.527,
  swapShort: -1.104,
  leverage: 3.33,
  spreadRaw: 0.00008,
  spreadTable: 0.8,
  starting: null,
  swap_rollover3days: 0,
  marginMaintenance: 0,
  marginHedged: 0,
  initialMargin: 0,
  timeString: 'Fri Mar 12 21:59:59 CET 2021',
  shortSelling: true,
  currencyPair: true
}

As you can see, I can only see the response from the getSymbol (socket) request, but there are no signs from the getTickPrices subscription. Am I missing something?

peterszombati commented 3 years ago

When did you try it? on weekend you can not get data because FX market are closed

peterszombati commented 3 years ago

also tip: in onReady callback dont use listener callback (x.Stream.listen.getTickPrices) function because its doing a duplicated listening after connection failure @CamiloManrique

CamiloManrique commented 3 years ago

Oh you are right. That was dumb of me. Tried with Bitcoin instead and the stream is working fine. Thanks!