@pioneer-platform/markets 8.3.6 → 8.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +95 -273
- package/package.json +2 -1
package/lib/index.js
CHANGED
|
@@ -82,6 +82,7 @@ axiosRetry(axios, {
|
|
|
82
82
|
return error.response.status === 503;
|
|
83
83
|
},
|
|
84
84
|
});
|
|
85
|
+
var ProToken = require("@pioneer-platform/pro-token");
|
|
85
86
|
var log = require('@pioneer-platform/loggerdog')();
|
|
86
87
|
var _c = require("@pioneer-platform/pioneer-coins"), getExplorerAddressUrl = _c.getExplorerAddressUrl, needsMemoByNetwork = _c.needsMemoByNetwork, COIN_MAP_LONG = _c.COIN_MAP_LONG;
|
|
87
88
|
var _d = require('@pioneer-platform/default-redis'), subscriber = _d.subscriber, publisher = _d.publisher, redis = _d.redis, redisQueue = _d.redisQueue;
|
|
@@ -104,7 +105,7 @@ module.exports = {
|
|
|
104
105
|
return get_assets_coingecko(limit, skip);
|
|
105
106
|
},
|
|
106
107
|
getRatePro: function () {
|
|
107
|
-
return
|
|
108
|
+
return ProToken.getRateProUsd();
|
|
108
109
|
},
|
|
109
110
|
updateCache: function () {
|
|
110
111
|
return update_cache();
|
|
@@ -161,7 +162,7 @@ var update_cache = function () {
|
|
|
161
162
|
return [4 /*yield*/, redis.setex(key, 3600, JSON.stringify(entry))];
|
|
162
163
|
case 2:
|
|
163
164
|
result_2 = _b.sent();
|
|
164
|
-
log.
|
|
165
|
+
log.debug(tag, "saved: " + key + " result: ", result_2);
|
|
165
166
|
_b.label = 3;
|
|
166
167
|
case 3:
|
|
167
168
|
j++;
|
|
@@ -190,12 +191,12 @@ var update_cache = function () {
|
|
|
190
191
|
case 7:
|
|
191
192
|
if (!(page <= totalPages)) return [3 /*break*/, 15];
|
|
192
193
|
url_1 = "".concat(URL_COINGECKO, "coins/markets?vs_currency=usd&order=market_cap_desc&per_page=").concat(limit, "&page=").concat(page, "&sparkline=false");
|
|
193
|
-
log.
|
|
194
|
+
log.debug(tag, "Fetching URL: ", url_1);
|
|
194
195
|
return [4 /*yield*/, axios.get(url_1)];
|
|
195
196
|
case 8:
|
|
196
197
|
result_1 = _a.sent();
|
|
197
198
|
allCoinsArray_2 = result_1.data;
|
|
198
|
-
log.
|
|
199
|
+
log.debug(tag, "Fetched ".concat(allCoinsArray_2.length, " coins for page ").concat(page));
|
|
199
200
|
_loop_2 = function (coin) {
|
|
200
201
|
var matchingAssets, _c, matchingAssets_1, matchingAsset, key;
|
|
201
202
|
return __generator(this, function (_d) {
|
|
@@ -211,7 +212,7 @@ var update_cache = function () {
|
|
|
211
212
|
return [4 /*yield*/, redis.setex(key, 3600, JSON.stringify(coin))];
|
|
212
213
|
case 2:
|
|
213
214
|
_d.sent();
|
|
214
|
-
log.
|
|
215
|
+
log.debug(tag, "Saved ".concat(coin.symbol, " under ").concat(key));
|
|
215
216
|
_d.label = 3;
|
|
216
217
|
case 3:
|
|
217
218
|
_c++;
|
|
@@ -234,7 +235,7 @@ var update_cache = function () {
|
|
|
234
235
|
return [3 /*break*/, 9];
|
|
235
236
|
case 12:
|
|
236
237
|
if (!(page < totalPages)) return [3 /*break*/, 14];
|
|
237
|
-
log.
|
|
238
|
+
log.debug(tag, "Waiting 10 seconds before next query...");
|
|
238
239
|
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 30000); })];
|
|
239
240
|
case 13:
|
|
240
241
|
_a.sent();
|
|
@@ -252,37 +253,16 @@ var update_cache = function () {
|
|
|
252
253
|
});
|
|
253
254
|
});
|
|
254
255
|
};
|
|
255
|
-
var get_pro_rate = function () {
|
|
256
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
257
|
-
var url, ratePro, e_2;
|
|
258
|
-
return __generator(this, function (_a) {
|
|
259
|
-
switch (_a.label) {
|
|
260
|
-
case 0:
|
|
261
|
-
_a.trys.push([0, 2, , 3]);
|
|
262
|
-
url = 'https://pioneers.dev/api/v1/uniswap/rateEth/0xef743df8eda497bcf1977393c401a636518dd630/8453';
|
|
263
|
-
return [4 /*yield*/, axios.get(url)];
|
|
264
|
-
case 1:
|
|
265
|
-
ratePro = _a.sent();
|
|
266
|
-
return [2 /*return*/, ratePro.data];
|
|
267
|
-
case 2:
|
|
268
|
-
e_2 = _a.sent();
|
|
269
|
-
console.error(e_2);
|
|
270
|
-
return [2 /*return*/, undefined];
|
|
271
|
-
case 3: return [2 /*return*/];
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
};
|
|
276
256
|
var build_balances = function (marketInfoCoinCap, marketInfoCoinGecko, pubkeys) {
|
|
277
257
|
return __awaiter(this, void 0, void 0, function () {
|
|
278
|
-
var tag, valuesUsd, totalValueUsd, outputBalances, unknownTokens, unPricedTokens,
|
|
258
|
+
var tag, valuesUsd, totalValueUsd, outputBalances, unknownTokens, unPricedTokens, i, entry, proUsdRate, coincap, coingecko, priceUsd, balance, valueUsd, e_2;
|
|
279
259
|
return __generator(this, function (_a) {
|
|
280
260
|
switch (_a.label) {
|
|
281
261
|
case 0:
|
|
282
262
|
tag = TAG + ' | build_balances | ';
|
|
283
263
|
_a.label = 1;
|
|
284
264
|
case 1:
|
|
285
|
-
_a.trys.push([1,
|
|
265
|
+
_a.trys.push([1, 12, , 13]);
|
|
286
266
|
if (!pubkeys)
|
|
287
267
|
throw Error("No pubkeys given!");
|
|
288
268
|
if (!!marketInfoCoinCap) return [3 /*break*/, 3];
|
|
@@ -307,249 +287,91 @@ var build_balances = function (marketInfoCoinCap, marketInfoCoinGecko, pubkeys)
|
|
|
307
287
|
outputBalances = [];
|
|
308
288
|
unknownTokens = [];
|
|
309
289
|
unPricedTokens = [];
|
|
310
|
-
|
|
290
|
+
i = 0;
|
|
291
|
+
_a.label = 6;
|
|
311
292
|
case 6:
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
//clone
|
|
317
|
-
if (entry.ticker === 'PRO') {
|
|
318
|
-
console.log("proRate: ", proRate);
|
|
319
|
-
ethToUsdRate = marketInfoCoinCap['ETH'].priceUsd || marketInfoCoinGecko['ETH'].current_price;
|
|
320
|
-
console.log("ethToUsdRate: ", ethToUsdRate);
|
|
321
|
-
proUsdRate = (1 / proRate) * ethToUsdRate;
|
|
322
|
-
redis.set('proUsdRate');
|
|
323
|
-
console.log("proToUsdRate: ", proUsdRate);
|
|
324
|
-
entry.priceUsd = proUsdRate;
|
|
325
|
-
//TODO get rate in USD
|
|
326
|
-
entry.rank = 10;
|
|
327
|
-
entry.alias = [];
|
|
328
|
-
entry.alias.push('PRO');
|
|
329
|
-
entry.source = "uniswap";
|
|
330
|
-
entry.symbol = "PRO";
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
coincap = marketInfoCoinCap[entry.ticker];
|
|
334
|
-
coingecko = marketInfoCoinGecko[entry.ticker];
|
|
335
|
-
// log.info("coincap: ",coincap)
|
|
336
|
-
// log.info("coingecko: ",coingecko)
|
|
337
|
-
if (!coincap && !coingecko) {
|
|
338
|
-
console.error("unknown token! ", entry.symbol);
|
|
339
|
-
unknownTokens.push(entry);
|
|
340
|
-
}
|
|
341
|
-
if (coincap && coincap.priceUsd) {
|
|
342
|
-
entry.priceUsd = coincap.priceUsd;
|
|
343
|
-
entry.rank = coincap.rank;
|
|
344
|
-
entry.alias = [];
|
|
345
|
-
if (!entry.name)
|
|
346
|
-
entry.name = coincap.name;
|
|
347
|
-
if (entry.name)
|
|
348
|
-
entry.alias.push(entry.name);
|
|
349
|
-
// entry.marketInfo = coincap
|
|
350
|
-
entry.source = "coincap";
|
|
351
|
-
}
|
|
352
|
-
//preference coinGecko as more accurate
|
|
353
|
-
if (coingecko && coingecko.current_price) {
|
|
354
|
-
entry.alias = [];
|
|
355
|
-
if (entry.name)
|
|
356
|
-
entry.alias.push(entry.name);
|
|
357
|
-
entry.priceUsd = coingecko.current_price;
|
|
358
|
-
if (!entry.name)
|
|
359
|
-
entry.name = coingecko.id;
|
|
360
|
-
entry.alias = entry.alias.push(coingecko.name);
|
|
361
|
-
entry.rank = coingecko.market_cap_rank;
|
|
362
|
-
entry.source = "coingecko";
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
priceUsd = Number(entry.priceUsd);
|
|
366
|
-
if (!isNaN(priceUsd) && priceUsd !== 0) {
|
|
367
|
-
balance = Number(entry.balance) || 0;
|
|
368
|
-
valueUsd = balance * priceUsd;
|
|
369
|
-
// Convert valueUsd to string and store back on the entry
|
|
370
|
-
entry.valueUsd = String(valueUsd);
|
|
371
|
-
// Add valueUsd to totalValueUsd, ensure totalValueUsd is a number
|
|
372
|
-
totalValueUsd += valueUsd;
|
|
373
|
-
// Push the entry to the output balances
|
|
374
|
-
outputBalances.push(entry);
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
// Push the entry to unPricedTokens if priceUsd is not valid
|
|
378
|
-
unPricedTokens.push(entry);
|
|
379
|
-
}
|
|
380
|
-
//get value
|
|
381
|
-
//get hit on ticker
|
|
382
|
-
//validate on chain
|
|
383
|
-
// //network from asset
|
|
384
|
-
// let network = COIN_MAP_LONG[symbol]
|
|
385
|
-
// if(network){
|
|
386
|
-
// //address explorer URL
|
|
387
|
-
// entry.addressUrl = getExplorerAddressUrl(entry.address,network,symbol,false)
|
|
388
|
-
// // needsMemo
|
|
389
|
-
// let needsMemo = needsMemoByNetwork(network)
|
|
390
|
-
// if(needsMemo) entry.needsMemo = true
|
|
391
|
-
// }
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
// //log.debug(tag,"entry: ",entry)
|
|
395
|
-
// //coinInfo
|
|
396
|
-
// let coinInfoCoinCap = marketInfoCoinCap[symbol]
|
|
397
|
-
// log.debug(tag,"coinInfoCoinCap: ",coinInfoCoinCap)
|
|
398
|
-
//
|
|
399
|
-
// //log.debug(tag,"marketInfoCoinGecko: ",marketInfoCoinGecko)
|
|
400
|
-
// let coinInfoCoinGecko = marketInfoCoinGecko[symbol]
|
|
401
|
-
// log.debug(tag,"coinInfoCoinGecko: ",coinInfoCoinGecko)
|
|
402
|
-
//
|
|
403
|
-
// let rateUsdCoinCap = 0
|
|
404
|
-
// if(coinInfoCoinCap && coinInfoCoinCap.priceUsd){
|
|
405
|
-
// rateUsdCoinCap = coinInfoCoinCap.priceUsd
|
|
406
|
-
// } else {
|
|
407
|
-
// //log.error(tag," COINCAP Missing rate data for "+symbol)
|
|
408
|
-
// }
|
|
409
|
-
//
|
|
410
|
-
// //
|
|
411
|
-
// let rateUsdCoinGecko = 0
|
|
412
|
-
// if(coinInfoCoinGecko && coinInfoCoinGecko.current_price){
|
|
413
|
-
// rateUsdCoinGecko = coinInfoCoinGecko.current_price
|
|
414
|
-
// } else {
|
|
415
|
-
// //log.error(tag," COINGECKO Missing rate data for "+symbol)
|
|
416
|
-
// }
|
|
417
|
-
//
|
|
418
|
-
// log.debug(symbol," rateUsdCoinCap: ",rateUsdCoinCap)
|
|
419
|
-
// log.debug(symbol," rateUsdCoinGecko: ",rateUsdCoinGecko)
|
|
420
|
-
//
|
|
421
|
-
// let relDiff = function(a:number, b:number) {
|
|
422
|
-
// return 100 * Math.abs( ( a - b ) / ( (a+b)/2 ) );
|
|
423
|
-
// }
|
|
424
|
-
//
|
|
425
|
-
// //if either = 0, then accept other price
|
|
426
|
-
// //flag Danger
|
|
427
|
-
//
|
|
428
|
-
// //Calculate the percent.
|
|
429
|
-
// var percent = relDiff(Number(rateUsdCoinCap),Number(rateUsdCoinGecko))
|
|
430
|
-
// log.debug(symbol," percent: ",percent)
|
|
431
|
-
// //percent diff
|
|
432
|
-
//
|
|
433
|
-
// /*
|
|
434
|
-
// Algo
|
|
435
|
-
// if any are 0, use other
|
|
436
|
-
// if both, choose lowest
|
|
437
|
-
// */
|
|
438
|
-
//
|
|
439
|
-
// let chosenRate = 0
|
|
440
|
-
// if(rateUsdCoinCap === 0){
|
|
441
|
-
// chosenRate = rateUsdCoinGecko
|
|
442
|
-
// } else if(rateUsdCoinGecko === 0){
|
|
443
|
-
// chosenRate = rateUsdCoinCap
|
|
444
|
-
// } else if(rateUsdCoinGecko > rateUsdCoinCap){
|
|
445
|
-
// chosenRate = rateUsdCoinCap
|
|
446
|
-
// } else {
|
|
447
|
-
// chosenRate = rateUsdCoinGecko
|
|
448
|
-
// }
|
|
449
|
-
// chosenRate = Number(chosenRate)
|
|
450
|
-
// entry.priceUsd = String(chosenRate)
|
|
451
|
-
// let valueUsd = entry.balance * chosenRate
|
|
452
|
-
// entry.valueUsd = String(valueUsd)
|
|
453
|
-
//
|
|
454
|
-
// //valueUsd
|
|
455
|
-
// totalValueUsd = Number(totalValueUsd) + Number(valueUsd)
|
|
456
|
-
//
|
|
457
|
-
// //TODO if quote !== USD
|
|
458
|
-
// //calc conversion
|
|
459
|
-
//
|
|
460
|
-
// let balance:any = JSON.parse(JSON.stringify(pubkey))
|
|
461
|
-
// delete balance.balances
|
|
462
|
-
// balance = {...balance,...entry}
|
|
463
|
-
// log.debug(tag,"pubkey: at (init):",pubkey)
|
|
464
|
-
// log.debug(tag,"balance: (init):",balance)
|
|
465
|
-
//
|
|
466
|
-
//
|
|
467
|
-
// if(coinInfoCoinCap){
|
|
468
|
-
// balance.onCoinCap = true
|
|
469
|
-
// if(balance.symbol && balance.symbol !== coinInfoCoinCap.symbol){
|
|
470
|
-
// //symbol mismatch
|
|
471
|
-
// balance.coincapAgreeSymbol = false
|
|
472
|
-
// balance.coincapSymbol = coinInfoCoinCap.symbol
|
|
473
|
-
// }
|
|
474
|
-
// let coincapInfo = {
|
|
475
|
-
// id_coincap: coinInfoCoinCap.id,
|
|
476
|
-
// rank_coincap: coinInfoCoinCap.rank,
|
|
477
|
-
// name_coincap: coinInfoCoinCap.name,
|
|
478
|
-
// supply: coinInfoCoinCap.supply,
|
|
479
|
-
// maxSupply: coinInfoCoinCap.maxSupply,
|
|
480
|
-
// marketCapUsd: coinInfoCoinCap.marketCapUsd,
|
|
481
|
-
// volumeUsd24Hr: coinInfoCoinCap.volumeUsd24Hr,
|
|
482
|
-
// priceUsd: coinInfoCoinCap.priceUsd,
|
|
483
|
-
// changePercent24Hr: coinInfoCoinCap.changePercent24Hr,
|
|
484
|
-
// vwap24Hr: coinInfoCoinCap.vwap24Hr,
|
|
485
|
-
// explorer: coinInfoCoinCap.explorer,
|
|
486
|
-
// }
|
|
487
|
-
// balance = {...balance,...coincapInfo}
|
|
488
|
-
// }else{
|
|
489
|
-
// balance.onCoinCap = false
|
|
490
|
-
// }
|
|
491
|
-
//
|
|
492
|
-
// if(coinInfoCoinGecko){
|
|
493
|
-
// log.debug(coinInfoCoinGecko.symbol," cginfo: ",coinInfoCoinGecko)
|
|
494
|
-
// balance.onCoinGecko = true
|
|
495
|
-
// if(balance.symbol && balance.symbol !== coinInfoCoinGecko.symbol){
|
|
496
|
-
// //symbol mismatch
|
|
497
|
-
// balance.coinGeckoAgreeSymbol = false
|
|
498
|
-
// balance.coinGeckoSymbol = coinInfoCoinGecko.symbol
|
|
499
|
-
// }
|
|
500
|
-
// let coinGeckoInfo = {
|
|
501
|
-
// name_coingecko: coinInfoCoinGecko.name,
|
|
502
|
-
// rank_coingecko: coinInfoCoinGecko.market_cap_rank,
|
|
503
|
-
// id_coingecko: coinInfoCoinGecko.id,
|
|
504
|
-
// image: coinInfoCoinGecko.image,
|
|
505
|
-
// current_price: coinInfoCoinGecko.current_price,
|
|
506
|
-
// market_cap: coinInfoCoinGecko.market_cap,
|
|
507
|
-
// fully_diluted_valuation: coinInfoCoinGecko.fully_diluted_valuation,
|
|
508
|
-
// total_volume: coinInfoCoinGecko.total_volume,
|
|
509
|
-
// high_24h: coinInfoCoinGecko.high_24h,
|
|
510
|
-
// low_24h: coinInfoCoinGecko.low_24h,
|
|
511
|
-
// price_change_24h: coinInfoCoinGecko.price_change_24h,
|
|
512
|
-
// price_change_percentage_24h: coinInfoCoinGecko.price_change_percentage_24h,
|
|
513
|
-
// market_cap_change_24h: coinInfoCoinGecko.market_cap_change_24h,
|
|
514
|
-
// market_cap_change_percentage_24h: coinInfoCoinGecko.market_cap_change_percentage_24h,
|
|
515
|
-
// circulating_supply: coinInfoCoinGecko.circulating_supply,
|
|
516
|
-
// total_supply: coinInfoCoinGecko.total_supply,
|
|
517
|
-
// max_supply: coinInfoCoinGecko.max_supply,
|
|
518
|
-
// ath: coinInfoCoinGecko.ath,
|
|
519
|
-
// ath_change_percentage: coinInfoCoinGecko.ath_change_percentage,
|
|
520
|
-
// ath_date: coinInfoCoinGecko.ath_date,
|
|
521
|
-
// atl: coinInfoCoinGecko.atl,
|
|
522
|
-
// atl_change_percentage: coinInfoCoinGecko.atl_change_percentage,
|
|
523
|
-
// atl_date: coinInfoCoinGecko.atl_date,
|
|
524
|
-
// roi: coinInfoCoinGecko.roi,
|
|
525
|
-
// last_updated: coinInfoCoinGecko.last_updated
|
|
526
|
-
// }
|
|
527
|
-
// balance = {...balance,...coinGeckoInfo}
|
|
528
|
-
// }else{
|
|
529
|
-
// balance.onCoinCap = false
|
|
530
|
-
// }
|
|
531
|
-
//
|
|
532
|
-
// //figure out icon
|
|
533
|
-
// if(!balance.image){
|
|
534
|
-
// //TODO lookup if icon exists, else use network icon
|
|
535
|
-
// //use network image? coincap
|
|
536
|
-
// balance.image = `https://static.coincap.io/assets/icons/${balance.symbol.toLowerCase()}@2x.png`
|
|
537
|
-
// }
|
|
538
|
-
// balances.push(balance)
|
|
539
|
-
}
|
|
540
|
-
return [2 /*return*/, { outputBalances: outputBalances, unPricedTokens: unPricedTokens, unknownTokens: unknownTokens, total: totalValueUsd }];
|
|
293
|
+
if (!(i < pubkeys.length)) return [3 /*break*/, 11];
|
|
294
|
+
entry = pubkeys[i];
|
|
295
|
+
if (!(entry.ticker === 'PRO')) return [3 /*break*/, 8];
|
|
296
|
+
return [4 /*yield*/, ProToken.getRateProUsd()];
|
|
541
297
|
case 7:
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
298
|
+
proUsdRate = _a.sent();
|
|
299
|
+
redis.set('proUsdRate', proUsdRate);
|
|
300
|
+
console.log("proToUsdRate: ", proUsdRate);
|
|
301
|
+
entry.priceUsd = proUsdRate;
|
|
302
|
+
//TODO get rate in USD
|
|
303
|
+
entry.rank = 10;
|
|
304
|
+
entry.alias = [];
|
|
305
|
+
entry.alias.push('PRO');
|
|
306
|
+
entry.source = "uniswap";
|
|
307
|
+
entry.symbol = "PRO";
|
|
308
|
+
return [3 /*break*/, 9];
|
|
309
|
+
case 8:
|
|
310
|
+
coincap = marketInfoCoinCap[entry.ticker];
|
|
311
|
+
coingecko = marketInfoCoinGecko[entry.ticker];
|
|
312
|
+
// log.debug("coincap: ",coincap)
|
|
313
|
+
// log.debug("coingecko: ",coingecko)
|
|
314
|
+
if (!coincap && !coingecko) {
|
|
315
|
+
//console.error("unknown token! ",entry.symbol)
|
|
316
|
+
unknownTokens.push(entry);
|
|
317
|
+
}
|
|
318
|
+
if (coincap && coincap.priceUsd) {
|
|
319
|
+
entry.priceUsd = coincap.priceUsd;
|
|
320
|
+
entry.rank = coincap.rank;
|
|
321
|
+
entry.alias = [];
|
|
322
|
+
if (!entry.name)
|
|
323
|
+
entry.name = coincap.name;
|
|
324
|
+
if (entry.name)
|
|
325
|
+
entry.alias.push(entry.name);
|
|
326
|
+
// entry.marketInfo = coincap
|
|
327
|
+
entry.source = "coincap";
|
|
328
|
+
}
|
|
329
|
+
//preference coinGecko as more accurate
|
|
330
|
+
if (coingecko && coingecko.current_price) {
|
|
331
|
+
entry.alias = [];
|
|
332
|
+
if (entry.name)
|
|
333
|
+
entry.alias.push(entry.name);
|
|
334
|
+
entry.priceUsd = coingecko.current_price;
|
|
335
|
+
if (!entry.name)
|
|
336
|
+
entry.name = coingecko.id;
|
|
337
|
+
entry.alias = entry.alias.push(coingecko.name);
|
|
338
|
+
entry.rank = coingecko.market_cap_rank;
|
|
339
|
+
entry.source = "coingecko";
|
|
340
|
+
}
|
|
341
|
+
_a.label = 9;
|
|
342
|
+
case 9:
|
|
343
|
+
priceUsd = Number(entry.priceUsd);
|
|
344
|
+
if (!isNaN(priceUsd) && priceUsd !== 0) {
|
|
345
|
+
balance = Number(entry.balance) || 0;
|
|
346
|
+
valueUsd = balance * priceUsd;
|
|
347
|
+
// Convert valueUsd to string and store back on the entry
|
|
348
|
+
entry.valueUsd = String(valueUsd);
|
|
349
|
+
// Add valueUsd to totalValueUsd, ensure totalValueUsd is a number
|
|
350
|
+
totalValueUsd += valueUsd;
|
|
351
|
+
// Push the entry to the output balances
|
|
352
|
+
outputBalances.push(entry);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
// Push the entry to unPricedTokens if priceUsd is not valid
|
|
356
|
+
unPricedTokens.push(entry);
|
|
357
|
+
}
|
|
358
|
+
_a.label = 10;
|
|
359
|
+
case 10:
|
|
360
|
+
i++;
|
|
361
|
+
return [3 /*break*/, 6];
|
|
362
|
+
case 11: return [2 /*return*/, { outputBalances: outputBalances, unPricedTokens: unPricedTokens, unknownTokens: unknownTokens, total: totalValueUsd }];
|
|
363
|
+
case 12:
|
|
364
|
+
e_2 = _a.sent();
|
|
365
|
+
console.error(tag, 'Error: ', e_2);
|
|
366
|
+
throw e_2;
|
|
367
|
+
case 13: return [2 /*return*/];
|
|
546
368
|
}
|
|
547
369
|
});
|
|
548
370
|
});
|
|
549
371
|
};
|
|
550
372
|
var get_assets_coincap = function () {
|
|
551
373
|
return __awaiter(this, void 0, void 0, function () {
|
|
552
|
-
var tag, output, url, result, allCoinsArray, i, coinInfo,
|
|
374
|
+
var tag, output, url, result, allCoinsArray, i, coinInfo, e_3;
|
|
553
375
|
return __generator(this, function (_a) {
|
|
554
376
|
switch (_a.label) {
|
|
555
377
|
case 0:
|
|
@@ -578,7 +400,7 @@ var get_assets_coincap = function () {
|
|
|
578
400
|
log.debug('result: ', output);
|
|
579
401
|
return [2 /*return*/, output];
|
|
580
402
|
case 3:
|
|
581
|
-
|
|
403
|
+
e_3 = _a.sent();
|
|
582
404
|
//handle error gracefully
|
|
583
405
|
return [2 /*return*/, {}];
|
|
584
406
|
case 4: return [2 /*return*/];
|
|
@@ -588,7 +410,7 @@ var get_assets_coincap = function () {
|
|
|
588
410
|
};
|
|
589
411
|
var get_assets_coingecko = function (limit, skip) {
|
|
590
412
|
return __awaiter(this, void 0, void 0, function () {
|
|
591
|
-
var tag, output, url, result, allCoinsArray, i, coinInfo,
|
|
413
|
+
var tag, output, url, result, allCoinsArray, i, coinInfo, e_4;
|
|
592
414
|
return __generator(this, function (_a) {
|
|
593
415
|
switch (_a.label) {
|
|
594
416
|
case 0:
|
|
@@ -621,7 +443,7 @@ var get_assets_coingecko = function (limit, skip) {
|
|
|
621
443
|
log.debug('result: ', output);
|
|
622
444
|
return [2 /*return*/, output];
|
|
623
445
|
case 3:
|
|
624
|
-
|
|
446
|
+
e_4 = _a.sent();
|
|
625
447
|
//handle error gracefully
|
|
626
448
|
return [2 /*return*/, {}];
|
|
627
449
|
case 4: return [2 /*return*/];
|
|
@@ -631,7 +453,7 @@ var get_assets_coingecko = function (limit, skip) {
|
|
|
631
453
|
};
|
|
632
454
|
var get_prices_in_quote = function (assets, quote) {
|
|
633
455
|
return __awaiter(this, void 0, void 0, function () {
|
|
634
|
-
var tag, data,
|
|
456
|
+
var tag, data, e_5;
|
|
635
457
|
return __generator(this, function (_a) {
|
|
636
458
|
switch (_a.label) {
|
|
637
459
|
case 0:
|
|
@@ -644,8 +466,8 @@ var get_prices_in_quote = function (assets, quote) {
|
|
|
644
466
|
data = (_a.sent()).data;
|
|
645
467
|
return [2 /*return*/, data];
|
|
646
468
|
case 3:
|
|
647
|
-
|
|
648
|
-
log.error(tag, "e: ",
|
|
469
|
+
e_5 = _a.sent();
|
|
470
|
+
log.error(tag, "e: ", e_5);
|
|
649
471
|
return [3 /*break*/, 4];
|
|
650
472
|
case 4: return [2 /*return*/];
|
|
651
473
|
}
|
|
@@ -655,7 +477,7 @@ var get_prices_in_quote = function (assets, quote) {
|
|
|
655
477
|
var get_price = function (asset) {
|
|
656
478
|
var _a, _b, _c, _d;
|
|
657
479
|
return __awaiter(this, void 0, void 0, function () {
|
|
658
|
-
var tag, data, currency, marketData,
|
|
480
|
+
var tag, data, currency, marketData, e_6;
|
|
659
481
|
return __generator(this, function (_e) {
|
|
660
482
|
switch (_e.label) {
|
|
661
483
|
case 0:
|
|
@@ -678,8 +500,8 @@ var get_price = function (asset) {
|
|
|
678
500
|
icon: (_d = data === null || data === void 0 ? void 0 : data.image) === null || _d === void 0 ? void 0 : _d.large
|
|
679
501
|
}];
|
|
680
502
|
case 3:
|
|
681
|
-
|
|
682
|
-
log.error(tag, "e: ",
|
|
503
|
+
e_6 = _e.sent();
|
|
504
|
+
log.error(tag, "e: ", e_6);
|
|
683
505
|
return [3 /*break*/, 4];
|
|
684
506
|
case 4: return [2 /*return*/];
|
|
685
507
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/markets",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.8",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
8
8
|
"@pioneer-platform/pioneer-discovery": "^0.0.7",
|
|
9
9
|
"@pioneer-platform/pioneer-types": "^8.3.1",
|
|
10
|
+
"@pioneer-platform/pro-token": "^0.0.3",
|
|
10
11
|
"axios": "^1.3.4",
|
|
11
12
|
"axios-retry": "^3.2.0",
|
|
12
13
|
"dotenv": "^8.2.0"
|