Make sure exchange API response format is valid before using it

This commit is contained in:
nymkappa
2022-12-01 12:05:23 +01:00
parent 2b411aad0a
commit a671bfc226
6 changed files with 33 additions and 6 deletions

View File

@@ -127,7 +127,11 @@ class PriceUpdater {
// Compute average price, non weighted
prices = prices.filter(price => price > 0);
this.latestPrices[currency] = Math.round((prices.reduce((partialSum, a) => partialSum + a, 0)) / prices.length);
if (prices.length === 0) {
this.latestPrices[currency] = -1;
} else {
this.latestPrices[currency] = Math.round((prices.reduce((partialSum, a) => partialSum + a, 0)) / prices.length);
}
}
logger.info(`Latest BTC fiat averaged price: ${JSON.stringify(this.latestPrices)}`);