@icgio/icg-utils 1.7.59 → 1.7.61

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.
Files changed (2) hide show
  1. package/lib/crypto-rates.js +158 -101
  2. package/package.json +1 -1
@@ -236,10 +236,10 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
236
236
  }
237
237
  }
238
238
  coins_map = source === 'coingecko' ? process_coins_map_coingecko(coins_map_raw_coingecko) : process_coins_map_coinmarketcap(coins_map_raw_coinmarketcap)
239
- try {
240
- if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'BBDC')) {
241
- let curs = _.without(pair_or_pairs_or_cur_curs, 'BBDC')
242
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=BBDC_USDT&depth=100').then((res) => {
239
+ if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'BBDC')) {
240
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'BBDC')
241
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=BBDC_USDT&depth=100').then((res) => {
242
+ try {
243
243
  const { asks, bids } = res.body.data
244
244
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
245
245
  result.BBDC = {
@@ -247,10 +247,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
247
247
  USDT: rate,
248
248
  }
249
249
  get_crypto_rates(cb, curs, type, source)
250
- })
251
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DARK')) {
252
- let curs = _.without(pair_or_pairs_or_cur_curs, 'DARK')
253
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=DARK_USDT&depth=100').then((res) => {
250
+ } catch (error) {
251
+ console.error(error)
252
+ }
253
+ })
254
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DARK')) {
255
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'DARK')
256
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=DARK_USDT&depth=100').then((res) => {
257
+ try {
254
258
  const { asks, bids } = res.body.data
255
259
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
256
260
  result.DARK = {
@@ -258,10 +262,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
258
262
  USDT: rate,
259
263
  }
260
264
  get_crypto_rates(cb, curs, type, source)
261
- })
262
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DMC')) {
263
- let curs = _.without(pair_or_pairs_or_cur_curs, 'DMC')
264
- needle('get', 'https://api.gateio.ws/api/v4/spot/order_book?currency_pair=DMC_USDT').then((res) => {
265
+ } catch (error) {
266
+ console.error(error)
267
+ }
268
+ })
269
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DMC')) {
270
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'DMC')
271
+ needle('get', 'https://api.gateio.ws/api/v4/spot/order_book?currency_pair=DMC_USDT').then((res) => {
272
+ try {
265
273
  const { asks, bids } = res.body
266
274
  let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
267
275
  result.DMC = {
@@ -269,10 +277,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
269
277
  USDT: rate,
270
278
  }
271
279
  get_crypto_rates(cb, curs, type, source)
272
- })
273
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DFI')) {
274
- let curs = _.without(pair_or_pairs_or_cur_curs, 'DFI')
275
- needle('get', 'https://api.coinstore.com/api/v1/market/depth/dfiusdt').then((res) => {
280
+ } catch (error) {
281
+ console.error(error)
282
+ }
283
+ })
284
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'DFI')) {
285
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'DFI')
286
+ needle('get', 'https://api.coinstore.com/api/v1/market/depth/dfiusdt').then((res) => {
287
+ try {
276
288
  const asks = res.body.data.a
277
289
  const bids = res.body.data.b
278
290
  let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
@@ -281,10 +293,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
281
293
  USDT: rate,
282
294
  }
283
295
  get_crypto_rates(cb, curs, type, source)
284
- })
285
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'ENIX')) {
286
- let curs = _.without(pair_or_pairs_or_cur_curs, 'ENIX')
287
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=ENIX_USDT&depth=100').then((res) => {
296
+ } catch (error) {
297
+ console.error(error)
298
+ }
299
+ })
300
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'ENIX')) {
301
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'ENIX')
302
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=ENIX_USDT&depth=100').then((res) => {
303
+ try {
288
304
  const { asks, bids } = res.body.data
289
305
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
290
306
  result.ENIX = {
@@ -292,41 +308,54 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
292
308
  USDT: rate,
293
309
  }
294
310
  get_crypto_rates(cb, curs, type, source)
295
- })
296
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'FIRM')) {
297
- let curs = _.without(pair_or_pairs_or_cur_curs, 'FIRM')
298
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=FIRM_USDT&depth=100').then((res) => {
311
+ } catch (error) {
312
+ console.error(error)
313
+ }
314
+ })
315
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'FREN')) {
316
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'FREN')
317
+ dex_rate().then((res) => {
318
+ result.FREN = {
319
+ USD: res.FRENUSDT,
320
+ USDT: res.FRENUSDT,
321
+ }
322
+ get_crypto_rates(cb, curs, type, source)
323
+ })
324
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'GLW')) {
325
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'GLW')
326
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=GLW_USDT&depth=100').then((res) => {
327
+ try {
299
328
  const { asks, bids } = res.body.data
300
329
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
301
- result.FIRM = {
330
+ result.GLW = {
302
331
  USD: rate,
303
332
  USDT: rate,
304
333
  }
305
334
  get_crypto_rates(cb, curs, type, source)
306
- })
307
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'FREN')) {
308
- let curs = _.without(pair_or_pairs_or_cur_curs, 'FREN')
309
- dex_rate().then((res) => {
310
- result.FREN = {
311
- USD: res.FRENUSDT,
312
- USDT: res.FRENUSDT,
313
- }
314
- get_crypto_rates(cb, curs, type, source)
315
- })
316
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'GLW')) {
317
- let curs = _.without(pair_or_pairs_or_cur_curs, 'GLW')
318
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=GLW_USDT&depth=100').then((res) => {
319
- const { asks, bids } = res.body.data
320
- let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
321
- result.GLW = {
335
+ } catch (error) {
336
+ console.error(error)
337
+ }
338
+ })
339
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'GPT')) {
340
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'GPT')
341
+ needle('get', 'https://api.coinstore.com/api/v1/market/depth/gptusdt').then((res) => {
342
+ try {
343
+ const asks = res.body.data.a
344
+ const bids = res.body.data.b
345
+ let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
346
+ result.GPT = {
322
347
  USD: rate,
323
348
  USDT: rate,
324
349
  }
325
350
  get_crypto_rates(cb, curs, type, source)
326
- })
327
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'IUS')) {
328
- let curs = _.without(pair_or_pairs_or_cur_curs, 'IUS')
329
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=IUS_USDT&depth=100').then((res) => {
351
+ } catch (error) {
352
+ console.error(error)
353
+ }
354
+ })
355
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'IUS')) {
356
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'IUS')
357
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=IUS_USDT&depth=100').then((res) => {
358
+ try {
330
359
  const { asks, bids } = res.body.data
331
360
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
332
361
  result.IUS = {
@@ -334,10 +363,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
334
363
  USDT: rate,
335
364
  }
336
365
  get_crypto_rates(cb, curs, type, source)
337
- })
338
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'JD')) {
339
- let curs = _.without(pair_or_pairs_or_cur_curs, 'JD')
340
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=JD_USDT&depth=100').then((res) => {
366
+ } catch (error) {
367
+ console.error(error)
368
+ }
369
+ })
370
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'JD')) {
371
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'JD')
372
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=JD_USDT&depth=100').then((res) => {
373
+ try {
341
374
  const { asks, bids } = res.body.data
342
375
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
343
376
  result.JD = {
@@ -345,10 +378,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
345
378
  USDT: rate,
346
379
  }
347
380
  get_crypto_rates(cb, curs, type, source)
348
- })
349
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'KLC')) {
350
- let curs = _.without(pair_or_pairs_or_cur_curs, 'KLC')
351
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=KLC_USDT&depth=100').then((res) => {
381
+ } catch (error) {
382
+ console.error(error)
383
+ }
384
+ })
385
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'KLC')) {
386
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'KLC')
387
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=KLC_USDT&depth=100').then((res) => {
388
+ try {
352
389
  const { asks, bids } = res.body.data
353
390
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
354
391
  result.KLC = {
@@ -356,10 +393,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
356
393
  USDT: rate,
357
394
  }
358
395
  get_crypto_rates(cb, curs, type, source)
359
- })
360
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'MEGODS')) {
361
- let curs = _.without(pair_or_pairs_or_cur_curs, 'MEGODS')
362
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=MEGODS_USDT&depth=100').then((res) => {
396
+ } catch (error) {
397
+ console.error(error)
398
+ }
399
+ })
400
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'MEGODS')) {
401
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'MEGODS')
402
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=MEGODS_USDT&depth=100').then((res) => {
403
+ try {
363
404
  const { asks, bids } = res.body.data
364
405
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
365
406
  result.MEGODS = {
@@ -367,36 +408,44 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
367
408
  USDT: rate,
368
409
  }
369
410
  get_crypto_rates(cb, curs, type, source)
370
- })
371
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'MONE')) {
372
- let curs = _.without(pair_or_pairs_or_cur_curs, 'MONE')
373
- needle('get', 'https://www.bitforex.com/api/v1/market/depth?symbol=coin-usdt-mone').then((res) => {
374
- try {
375
- const { asks, bids } = JSON.parse(res.body).data
376
- let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
377
- result.MONE = {
378
- USD: rate,
379
- USDT: rate,
380
- }
381
- get_crypto_rates(cb, curs, type, source)
382
- } catch (error) {}
383
- })
384
- }
385
- // else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'ROACHCOIN')) {
386
- // let curs = _.without(pair_or_pairs_or_cur_curs, 'ROACHCOIN')
387
- // needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=ROACHCOIN_USDT&depth=100').then((res) => {
388
- // const { asks, bids } = res.body.data
389
- // let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
390
- // result.ROACHCOIN = {
391
- // USD: rate,
392
- // USDT: rate,
393
- // }
394
- // get_crypto_rates(cb, curs, type, source)
395
- // })
396
- // }
397
- else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'SDP')) {
398
- let curs = _.without(pair_or_pairs_or_cur_curs, 'SDP')
399
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=SDP_USDT&depth=100').then((res) => {
411
+ } catch (error) {
412
+ console.error(error)
413
+ }
414
+ })
415
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'MONE')) {
416
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'MONE')
417
+ needle('get', 'https://www.bitforex.com/api/v1/market/depth?symbol=coin-usdt-mone').then((res) => {
418
+ try {
419
+ const { asks, bids } = JSON.parse(res.body).data
420
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
421
+ result.MONE = {
422
+ USD: rate,
423
+ USDT: rate,
424
+ }
425
+ get_crypto_rates(cb, curs, type, source)
426
+ } catch (error) {
427
+ console.error(error)
428
+ }
429
+ })
430
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'ROACHCOIN')) {
431
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'ROACHCOIN')
432
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=ROACHCOIN_USDT&depth=100').then((res) => {
433
+ try {
434
+ const { asks, bids } = res.body.data
435
+ let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
436
+ result.ROACHCOIN = {
437
+ USD: rate,
438
+ USDT: rate,
439
+ }
440
+ get_crypto_rates(cb, curs, type, source)
441
+ } catch (error) {
442
+ console.error(error)
443
+ }
444
+ })
445
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'SDP')) {
446
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'SDP')
447
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=SDP_USDT&depth=100').then((res) => {
448
+ try {
400
449
  const { asks, bids } = res.body.data
401
450
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
402
451
  result.SDP = {
@@ -404,10 +453,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
404
453
  USDT: rate,
405
454
  }
406
455
  get_crypto_rates(cb, curs, type, source)
407
- })
408
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'SPAI')) {
409
- let curs = _.without(pair_or_pairs_or_cur_curs, 'SPAI')
410
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=SPAI_USDT&depth=100').then((res) => {
456
+ } catch (error) {
457
+ console.error(error)
458
+ }
459
+ })
460
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'SPAI')) {
461
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'SPAI')
462
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=SPAI_USDT&depth=100').then((res) => {
463
+ try {
411
464
  const { asks, bids } = res.body.data
412
465
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
413
466
  result.SPAI = {
@@ -415,10 +468,14 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
415
468
  USDT: rate,
416
469
  }
417
470
  get_crypto_rates(cb, curs, type, source)
418
- })
419
- } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'TIN')) {
420
- let curs = _.without(pair_or_pairs_or_cur_curs, 'TIN')
421
- needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=TIN_USDT&depth=100').then((res) => {
471
+ } catch (error) {
472
+ console.error(error)
473
+ }
474
+ })
475
+ } else if (type === 'curs' && _.includes(pair_or_pairs_or_cur_curs, 'TIN')) {
476
+ let curs = _.without(pair_or_pairs_or_cur_curs, 'TIN')
477
+ needle('get', 'https://www.mexc.com/open/api/v2/market/depth?symbol=TIN_USDT&depth=100').then((res) => {
478
+ try {
422
479
  const { asks, bids } = res.body.data
423
480
  let rate = (parseFloat(asks[0].price) + parseFloat(bids[0].price)) / 2
424
481
  result.TIN = {
@@ -426,12 +483,12 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
426
483
  USDT: rate,
427
484
  }
428
485
  get_crypto_rates(cb, curs, type, source)
429
- })
430
- } else {
431
- get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type)
432
- }
433
- } catch (error) {
434
- console.log('get_crypto_rates', error)
486
+ } catch (error) {
487
+ console.error(error)
488
+ }
489
+ })
490
+ } else {
491
+ get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type)
435
492
  }
436
493
  }
437
494
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.7.59",
3
+ "version": "1.7.61",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {