Skip to content

Commit 3dff6f9

Browse files
committed
Improve stale price handling.
1 parent 9f10b48 commit 3dff6f9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/data-feeds/ccxt-provider-service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export class CcxtFeed implements BaseDataFeed {
233233

234234
for (const source of config.sources) {
235235
const exchange: Exchange = this.exchangeByName.get(source.exchange);
236+
if (exchange == undefined) continue;
236237
const market = exchange.markets[source.symbol];
237238
if (market == undefined) continue;
238239
this.logger.log(`Fetching last price for ${market.id} on ${source.exchange}`);
@@ -268,6 +269,12 @@ export class CcxtFeed implements BaseDataFeed {
268269

269270
// Normalize weights to sum to 1
270271
const weightSum = weights.reduce((sum, weight) => sum + weight, 0);
272+
273+
if (weightSum === 0) {
274+
// All prices extremely stale, return any
275+
return prices[0].value;
276+
}
277+
271278
const normalizedWeights = weights.map(weight => weight / weightSum);
272279

273280
// Combine prices and weights

0 commit comments

Comments
 (0)