@icgio/icg-utils 1.9.24 → 1.9.26
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/crypto-rates.js +5 -5
- package/lib/ip.js +17 -1
- package/package.json +1 -4
- package/lib/html-parser.js +0 -66
- package/lib/rate-limit-logger.js +0 -31
package/lib/crypto-rates.js
CHANGED
|
@@ -367,12 +367,12 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
|
|
|
367
367
|
}
|
|
368
368
|
})
|
|
369
369
|
} else if (exchange === 'mexc') {
|
|
370
|
-
let pair = cur + '
|
|
371
|
-
let url = `https://
|
|
370
|
+
let pair = cur + 'USDT'
|
|
371
|
+
let url = `https://api.mexc.com/api/v3/depth?symbol=${pair}`
|
|
372
372
|
limiter.process(needle.get, url, (err, res, body) => {
|
|
373
373
|
try {
|
|
374
|
-
const { asks, bids } = body
|
|
375
|
-
let rate = (parseFloat(asks[0]
|
|
374
|
+
const { asks, bids } = body
|
|
375
|
+
let rate = (parseFloat(asks[0][0]) + parseFloat(bids[0][0])) / 2
|
|
376
376
|
result[cur] = {
|
|
377
377
|
USD: rate,
|
|
378
378
|
USDT: rate,
|
|
@@ -576,7 +576,7 @@ let get_crypto_rates = (cb, pair_or_pairs_or_cur_curs, type, source = 'coingecko
|
|
|
576
576
|
// console.log(res)
|
|
577
577
|
// },
|
|
578
578
|
// {
|
|
579
|
-
//
|
|
579
|
+
// ETHF: 'mexc',
|
|
580
580
|
// },
|
|
581
581
|
// 'curs_dict'
|
|
582
582
|
// )
|
package/lib/ip.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Get external IP address using ipify.org API
|
|
3
|
+
* @returns {Promise<string>} The external IP address
|
|
4
|
+
*/
|
|
5
|
+
async function getIP() {
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch('https://api.ipify.org?format=json')
|
|
8
|
+
if (!response.ok) {
|
|
9
|
+
throw new Error(`HTTP error! status: ${response.status}`)
|
|
10
|
+
}
|
|
11
|
+
const data = await response.json()
|
|
12
|
+
return data.ip
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error('Error fetching external IP:', error.message)
|
|
15
|
+
throw error
|
|
16
|
+
}
|
|
17
|
+
}
|
|
2
18
|
|
|
3
19
|
module.exports = getIP
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.26",
|
|
4
4
|
"description": "Utils package.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"directories": {
|
|
@@ -23,12 +23,9 @@
|
|
|
23
23
|
"@influxdata/influxdb-client": "^1.35.0",
|
|
24
24
|
"@influxdata/influxdb-client-apis": "^1.35.0",
|
|
25
25
|
"csv-parse": "^5.6.0",
|
|
26
|
-
"external-ip": "^2.3.1",
|
|
27
|
-
"htmlparser2": "^3.10.1",
|
|
28
26
|
"lodash": "^4.17.21",
|
|
29
27
|
"mailgun-js": "^0.22.0",
|
|
30
28
|
"needle": "^3.3.1",
|
|
31
|
-
"qrcode-terminal": "^0.12.0",
|
|
32
29
|
"websocket": "^1.0.35",
|
|
33
30
|
"winston": "^2.4.5",
|
|
34
31
|
"ws": "^8.18.3"
|
package/lib/html-parser.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const htmlparser = require('htmlparser2')
|
|
2
|
-
const needle = require('needle')
|
|
3
|
-
|
|
4
|
-
function tag_parser(body, tag_name, tag_attrs, cb) {
|
|
5
|
-
let result = []
|
|
6
|
-
let parser = new htmlparser.Parser(
|
|
7
|
-
{
|
|
8
|
-
onopentag: (name, attrs) => {
|
|
9
|
-
let flag = true
|
|
10
|
-
for (let tag_attr in tag_attrs) {
|
|
11
|
-
if (!attrs[tag_attr] || tag_attrs[tag_attr] !== attrs[tag_attr]) flag = false
|
|
12
|
-
}
|
|
13
|
-
if (flag && name === tag_name) {
|
|
14
|
-
result.push(attrs)
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
onend: () => {
|
|
18
|
-
cb(result)
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
{ decodeEntities: true }
|
|
22
|
-
)
|
|
23
|
-
parser.write(body)
|
|
24
|
-
parser.end()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function text_parser(body, include_new_line = false, cb) {
|
|
28
|
-
let result = []
|
|
29
|
-
let parser = new htmlparser.Parser(
|
|
30
|
-
{
|
|
31
|
-
ontext: (text) => {
|
|
32
|
-
if (!include_new_line && !text.startsWith('\n')) result.push(text)
|
|
33
|
-
},
|
|
34
|
-
onend: () => {
|
|
35
|
-
cb(result)
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
{ decodeEntities: true }
|
|
39
|
-
)
|
|
40
|
-
parser.write(body)
|
|
41
|
-
parser.end()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function html_parser(url, options, cb) {
|
|
45
|
-
let tag_name = options.tag_name
|
|
46
|
-
let tag_attrs = options.tag_attrs
|
|
47
|
-
let text = options.text
|
|
48
|
-
let text_include_new_line = options.text_include_new_line
|
|
49
|
-
if (tag_name && tag_attrs && text) {
|
|
50
|
-
console.error('unable to parse tag and text at the same time')
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
if (tag_name && tag_attrs) {
|
|
54
|
-
needle.get(url, (res, err, body) => {
|
|
55
|
-
tag_parser(body, tag_name, tag_attrs, cb)
|
|
56
|
-
})
|
|
57
|
-
} else if (text) {
|
|
58
|
-
needle.get(url, (res, err, body) => {
|
|
59
|
-
text_parser(body, text_include_new_line, cb)
|
|
60
|
-
})
|
|
61
|
-
} else {
|
|
62
|
-
console.error('wrong options')
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = html_parser
|
package/lib/rate-limit-logger.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
class RateLimitedLogger {
|
|
2
|
-
constructor(defaultLimit = 1000) {
|
|
3
|
-
this.defaultLimit = defaultLimit
|
|
4
|
-
this.lastLogTime = 0
|
|
5
|
-
this.lastErrorTime = 0
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
log(message, limit = this.defaultLimit) {
|
|
9
|
-
this._rateLimitedOutput(console.log, message, limit, 'log')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
error(message, limit = this.defaultLimit) {
|
|
13
|
-
this._rateLimitedOutput(console.error, message, limit, 'error')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
_rateLimitedOutput(outputFunction, message, limit, type) {
|
|
17
|
-
const now = Date.now()
|
|
18
|
-
const lastTime = type === 'log' ? this.lastLogTime : this.lastErrorTime
|
|
19
|
-
|
|
20
|
-
if (now - lastTime >= limit) {
|
|
21
|
-
outputFunction(message)
|
|
22
|
-
if (type === 'log') {
|
|
23
|
-
this.lastLogTime = now
|
|
24
|
-
} else {
|
|
25
|
-
this.lastErrorTime = now
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = RateLimitedLogger
|