@icgio/icg-utils 1.9.67 → 1.9.69
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/influxdb.js +30 -1
- package/lib/rates.js +13 -13
- package/lib/utils.js +1 -1
- package/package.json +1 -1
package/lib/influxdb.js
CHANGED
|
@@ -5,6 +5,15 @@ const { parse } = require('csv-parse')
|
|
|
5
5
|
const { InfluxDB, Point } = require('@influxdata/influxdb-client')
|
|
6
6
|
const { BucketsAPI } = require('@influxdata/influxdb-client-apis')
|
|
7
7
|
|
|
8
|
+
const reported_schema_gaps = new Set()
|
|
9
|
+
|
|
10
|
+
function report_schema_gap(key, ...message) {
|
|
11
|
+
if (!reported_schema_gaps.has(key)) {
|
|
12
|
+
reported_schema_gaps.add(key)
|
|
13
|
+
console.error(...message)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
8
17
|
function fields_check(fields) {
|
|
9
18
|
let result = true
|
|
10
19
|
for (let key in fields) {
|
|
@@ -58,12 +67,29 @@ class Influx {
|
|
|
58
67
|
this.bucket_exist = true
|
|
59
68
|
}
|
|
60
69
|
}
|
|
70
|
+
let dropped_points = 0
|
|
71
|
+
let dropped_fields = 0
|
|
61
72
|
points = points
|
|
73
|
+
.map((point) => {
|
|
74
|
+
if (typeof point.timestamp === 'number' || typeof point.timestamp === 'string') {
|
|
75
|
+
const timestamp = new Date(point.timestamp)
|
|
76
|
+
if (!_.isNaN(timestamp.getTime())) {
|
|
77
|
+
return { ...point, timestamp }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return point
|
|
81
|
+
})
|
|
62
82
|
.filter((point) => {
|
|
83
|
+
if (!_.get(this.schema, [point.measurement, 'fields'])) {
|
|
84
|
+
report_schema_gap(point.measurement, 'influx unknown measurement, points dropped:', point.measurement)
|
|
85
|
+
dropped_points++
|
|
86
|
+
return false
|
|
87
|
+
}
|
|
63
88
|
if (fields_check(point.fields) && (!point.timestamp || point.timestamp instanceof Date)) {
|
|
64
89
|
return true
|
|
65
90
|
} else {
|
|
66
91
|
console.error('influx check_points', point)
|
|
92
|
+
dropped_points++
|
|
67
93
|
return false
|
|
68
94
|
}
|
|
69
95
|
})
|
|
@@ -80,6 +106,9 @@ class Influx {
|
|
|
80
106
|
p_temp = p_temp.intField(field, p.fields[field])
|
|
81
107
|
} else if (field_type === 'string') {
|
|
82
108
|
p_temp = p_temp.stringField(field, p.fields[field])
|
|
109
|
+
} else {
|
|
110
|
+
report_schema_gap(p.measurement + '.' + field, 'influx unknown field, dropped:', p.measurement, field)
|
|
111
|
+
dropped_fields++
|
|
83
112
|
}
|
|
84
113
|
}
|
|
85
114
|
if (p.timestamp) {
|
|
@@ -91,7 +120,7 @@ class Influx {
|
|
|
91
120
|
write_api
|
|
92
121
|
.close()
|
|
93
122
|
.then(() => {
|
|
94
|
-
cb({ success: true, body: points.length })
|
|
123
|
+
cb({ success: true, body: points.length, dropped_points, dropped_fields })
|
|
95
124
|
})
|
|
96
125
|
.catch((err) => {
|
|
97
126
|
cb({ success: false, body: err })
|
package/lib/rates.js
CHANGED
|
@@ -16,7 +16,12 @@ function get_forex_rate_usd(curs, cb) {
|
|
|
16
16
|
if (body && body.usd) {
|
|
17
17
|
let rates = {}
|
|
18
18
|
for (let cur of curs) {
|
|
19
|
-
|
|
19
|
+
const rate = body.usd[cur.toLowerCase()]
|
|
20
|
+
if (rate > 0) {
|
|
21
|
+
rates[cur] = 1 / rate
|
|
22
|
+
} else {
|
|
23
|
+
console.error('forex_rate missing:', cur)
|
|
24
|
+
}
|
|
20
25
|
}
|
|
21
26
|
cb(rates)
|
|
22
27
|
} else {
|
|
@@ -118,12 +123,12 @@ function _fetch_exchange_rates(cb, curs_dict) {
|
|
|
118
123
|
let exchange = curs_dict[cur]
|
|
119
124
|
let pair
|
|
120
125
|
|
|
121
|
-
if (exchange === '
|
|
122
|
-
pair = cur + '/USDT'
|
|
123
|
-
fetchMidPrice(cur, exchange, `https://ascendex.com/api/pro/v1/depth?symbol=${pair}`, (body) => midOf(body.data.data.asks, body.data.data.bids))
|
|
124
|
-
} else if (exchange === 'binance') {
|
|
126
|
+
if (exchange === 'binance') {
|
|
125
127
|
pair = cur + 'USDT'
|
|
126
128
|
fetchMidPrice(cur, exchange, `https://www.binance.com/api/v3/depth?symbol=${pair}&limit=20`, (body) => midOf(body.asks, body.bids))
|
|
129
|
+
} else if (exchange === 'binancefutures') {
|
|
130
|
+
pair = cur + 'USDT'
|
|
131
|
+
fetchMidPrice(cur, exchange, `https://fapi.binance.com/fapi/v1/depth?symbol=${pair}&limit=20`, (body) => midOf(body.asks, body.bids))
|
|
127
132
|
} else if (exchange === 'biconomy') {
|
|
128
133
|
pair = cur + '_USDT'
|
|
129
134
|
fetchMidPrice(cur, exchange, `https://api.biconomy.com/api/v1/depth?symbol=${pair}&size=5`, (body) => midOf(body.asks, body.bids))
|
|
@@ -133,10 +138,6 @@ function _fetch_exchange_rates(cb, curs_dict) {
|
|
|
133
138
|
} else if (exchange === 'bitget') {
|
|
134
139
|
pair = cur + 'USDT'
|
|
135
140
|
fetchMidPrice(cur, exchange, `https://api.bitget.com/api/v2/spot/market/orderbook?symbol=${pair}&type=step0`, (body) => midOf(body.data.asks, body.data.bids))
|
|
136
|
-
} else if (exchange === 'bitmart') {
|
|
137
|
-
pair = cur + '_USDT'
|
|
138
|
-
if (pair === 'ELON_USDT') pair = '$ELONSOL_USDT'
|
|
139
|
-
fetchMidPrice(cur, exchange, `https://api-cloud.bitmart.com/spot/v1/symbols/book?symbol=${pair}`, (body) => (parseFloat(body.data.sells[0].price) + parseFloat(body.data.buys[0].price)) / 2)
|
|
140
141
|
} else if (exchange === 'bybit') {
|
|
141
142
|
pair = cur + 'USDT'
|
|
142
143
|
fetchMidPrice(cur, exchange, `https://api.bybit.com/v5/market/orderbook?category=spot&symbol=${pair}&limit=20`, (body) => midOf(body.result.a, body.result.b))
|
|
@@ -149,13 +150,12 @@ function _fetch_exchange_rates(cb, curs_dict) {
|
|
|
149
150
|
fetchMidPrice(cur, exchange, `https://api.coinstore.com/api/v1/market/depth/${pair}`, (body) => midOf(body.data.a, body.data.b))
|
|
150
151
|
} else if (exchange === 'cryptocom') {
|
|
151
152
|
pair = cur + '_USDT'
|
|
152
|
-
fetchMidPrice(cur, exchange, `https://api.crypto.com/v2/public/get-book?instrument_name=${pair}&depth=20`, (body) =>
|
|
153
|
+
fetchMidPrice(cur, exchange, `https://api.crypto.com/v2/public/get-book?instrument_name=${pair}&depth=20`, (body) =>
|
|
154
|
+
midOf(body.result.data[0].asks, body.result.data[0].bids),
|
|
155
|
+
)
|
|
153
156
|
} else if (exchange === 'digifinex') {
|
|
154
157
|
pair = cur + '_USDT'
|
|
155
158
|
fetchMidPrice(cur, exchange, `https://openapi.digifinex.com/v3/spot/orderbook?symbol=${pair}`, (body) => midOf(body.data.asks, body.data.bids))
|
|
156
|
-
} else if (exchange === 'fastex') {
|
|
157
|
-
pair = cur.toUpperCase() + '-USDT'
|
|
158
|
-
fetchMidPrice(cur, exchange, `https://exchange.fastex.com/api/v1/orderbook/info?symbol=${pair}`, (body) => (parseFloat(body.response.entities.asks[0].price) + parseFloat(body.response.entities.bids[0].price)) / 2)
|
|
159
159
|
} else if (exchange === 'gate') {
|
|
160
160
|
pair = cur + '_USDT'
|
|
161
161
|
fetchMidPrice(cur, exchange, `https://api.gateio.ws/api/v4/spot/order_book?currency_pair=${pair}`, (body) => midOf(body.asks, body.bids))
|
package/lib/utils.js
CHANGED
|
@@ -446,7 +446,7 @@ function vol_position_combined(input_array, vol_target) {
|
|
|
446
446
|
break
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
|
-
avg_price = sum / vol ? sum / vol : price
|
|
449
|
+
let avg_price = sum / vol ? sum / vol : price
|
|
450
450
|
return { price, price_exchange, avg_price, vol, vol_exchange, sum, sum_exchange, pos, pos_exchange }
|
|
451
451
|
}
|
|
452
452
|
|