Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Asynchronous calls for getCandles #83

@4rocky4

Description

@4rocky4

I would like to calls getCandles multiple times in a promise loop.

function test(coinList) {
  var deferred = Q.defer();
  var promises = [];
  coinList.forEach(function (coin) {
    promises.push(getCandles(coin));
  });

  return Q.allSettled(promises).then(function (results) {

    var listMarkets = [];
    results.forEach(function (r) {
      console.log(r.value.MarketName);
    });

    return listMarkets;
  });

}

function getCandles(coin) {
  var deferred = Q.defer();
  bittrex.getcandles({
    marketName: coin.MarketName,
    tickInterval: 'hour', // intervals are keywords (oneMin, fiveMin, hour, thirtyMin, Day)
  }, function (data, err) {
        if (err) {
          console.log('1 err:' + coin.MarketName);
          deferred.resolve(coin);
        }

        if (data) {
          console.log('1 :' + coin.MarketName);
          coin.Test = 10;
          deferred.resolve(coin);
        }
      });

  return deferred.promise;
}
  • CoinList is a list of markets
    It works but I get some errors at one time.
...
1 :BTC-NEOS
1 :BTC-LGD
1 :BTC-SPR
1 :BTC-XMG
1 :BTC-VTC
1 :BTC-QTUM
1 :BTC-MAID
1 :BTC-DOPE
1 :BTC-EXCL
1 :BTC-PAY
1 :BTC-NLG
1 :BTC-REP
1 err:BTC-OMG
1 err:BTC-GAM
1 err:BTC-KORE
1 err:BTC-SNT
1 err:BTC-NAV
1 err:BTC-EFL
1 err:BTC-EBST
1 err:BTC-PKB

I tried to call the same market with each request, I have the same problem.

Should I change something in my function to fix it or is there a bug ?

Thanks for any help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions