@icgio/icg-utils 1.8.1 → 1.8.3

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.
@@ -7,7 +7,7 @@
7
7
  // }
8
8
 
9
9
  module.exports = {
10
- USDCNY: 7.233975,
11
- USDKRW: 1336.393712,
12
- USDTHB: 35.30959,
10
+ USDCNY: 7.28,
11
+ USDKRW: 1444.9,
12
+ USDTHB: 33.55,
13
13
  }
@@ -1 +1 @@
1
- module.exports = ['BUSD', 'CUSD', 'DAI', 'FEI', 'FRAX', 'GUSD', 'HUSD', 'IUSD', 'PAX', 'SUSD', 'TUSD', 'USDC', 'USDD', 'USDJ', 'USDK', 'USDP', 'USDT', 'IDR']
1
+ module.exports = ['BUSD', 'CUSD', 'DAI', 'FEI', 'FRAX', 'GUSD', 'PAX', 'SUSD', 'TUSD', 'USDC', 'USDD', 'USDJ', 'USDK', 'USDP', 'USDT']
@@ -184,8 +184,37 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
184
184
  let length = _.keys(curs_dict).length
185
185
  for (let cur in curs_dict) {
186
186
  let exchange = curs_dict[cur]
187
- if (exchange === 'bitmart') {
187
+ if (exchange === 'ascendex') {
188
+ let pair = cur + '/USDT'
189
+ let url = `https://ascendex.com/api/pro/v1/depth?symbol=${pair}`
190
+ limiter.process(needle.get, url, (err, res, body) => {
191
+ try {
192
+ const asks = body.data.data.asks
193
+ const bids = body.data.data.bids
194
+ let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
195
+ result[cur] = {
196
+ USD: rate,
197
+ USDT: rate,
198
+ }
199
+ let result_length = _.keys(result).length
200
+ if (result_length === length) {
201
+ for (let stable of stablecoins) {
202
+ result[stable] = {
203
+ USD: 1,
204
+ USDT: 1,
205
+ }
206
+ }
207
+ cb(result)
208
+ }
209
+ } catch (error) {
210
+ console.error(pair, error)
211
+ }
212
+ })
213
+ } else if (exchange === 'bitmart') {
188
214
  let pair = cur + '_USDT'
215
+ if ((pair = 'ELON_USDT')) {
216
+ pair = '$ELONSOL_USDT'
217
+ }
189
218
  let url = `https://api-cloud.bitmart.com/spot/v1/symbols/book?symbol=${pair}`
190
219
  limiter.process(needle.get, url, (err, res, body) => {
191
220
  try {
@@ -491,16 +520,17 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
491
520
  get_crypto_rates_base(cb, pair_or_pairs_or_cur_curs, type)
492
521
  }
493
522
 
494
- // get_crypto_rates(
495
- // (res) => {
496
- // console.log(res)
497
- // },
498
- // {
499
- // AXL: 'coingecko',
500
- // TLAND: 'fastex',
501
- // },
502
- // 'curs_dict'
503
- // )
523
+ get_crypto_rates(
524
+ (res) => {
525
+ console.log(res)
526
+ },
527
+ {
528
+ AXL: 'coingecko',
529
+ ELON: 'bitmart',
530
+ POLY: 'ascendex',
531
+ },
532
+ 'curs_dict'
533
+ )
504
534
 
505
535
  // get_crypto_rates(
506
536
  // (res) => {
@@ -1,12 +1,21 @@
1
1
  class RateLimitedLogger {
2
2
  constructor(defaultLimit = 1000) {
3
- this.defaultLimit = defaultLimit // Default time in milliseconds
4
- this.lastLogTime = 0
3
+ this.defaultLimit = defaultLimit // Shared default limit for log and error
4
+ this.lastLogTime = 0 // Tracks the last log or error time
5
5
  }
6
+
6
7
  log(message, limit = this.defaultLimit) {
8
+ this._rateLimitedOutput(console.log, message, limit)
9
+ }
10
+
11
+ error(message, limit = this.defaultLimit) {
12
+ this._rateLimitedOutput(console.error, message, limit)
13
+ }
14
+
15
+ _rateLimitedOutput(outputFunction, message, limit) {
7
16
  const now = Date.now()
8
17
  if (now - this.lastLogTime >= limit) {
9
- console.log(message)
18
+ outputFunction(message)
10
19
  this.lastLogTime = now
11
20
  }
12
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-utils",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "Utils package.",
5
5
  "main": "index.js",
6
6
  "directories": {