@icgio/icg-exchanges-wrapper 1.14.260 → 1.14.262
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/middleware/account.js +47 -47
- package/package.json +3 -3
package/middleware/account.js
CHANGED
|
@@ -35,13 +35,43 @@ module.exports = class Account {
|
|
|
35
35
|
|
|
36
36
|
console.log('exchange_assets_benchmarks', this.exchange_assets_benchmarks)
|
|
37
37
|
|
|
38
|
+
// Collect all unique currencies from balances and benchmarks
|
|
39
|
+
let all_currencies = new Set()
|
|
40
|
+
for (let exchange in initial_balances) {
|
|
41
|
+
for (let cur in initial_balances[exchange].total) {
|
|
42
|
+
if (initial_balances[exchange].total[cur] > 0) {
|
|
43
|
+
all_currencies.add(cur)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (let exchange in raw_benchmarks) {
|
|
48
|
+
for (let cur in raw_benchmarks[exchange]) {
|
|
49
|
+
all_currencies.add(cur)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let currencies_array = Array.from(all_currencies)
|
|
53
|
+
|
|
38
54
|
this.forex_rates = {}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
55
|
+
if (currencies_array.length > 0) {
|
|
56
|
+
forex_rate.get_forex_rate_usd(currencies_array, (res) => {
|
|
57
|
+
console.log('forex_rates', res)
|
|
58
|
+
this.forex_rates = res
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
get_rate_usd(cur, cmc_rates) {
|
|
63
|
+
// Unified rate resolution: forex_rates first, then cmc_rates fallback
|
|
64
|
+
if (this.forex_rates[cur]) {
|
|
65
|
+
return this.forex_rates[cur]
|
|
66
|
+
}
|
|
67
|
+
// Log warnings for missing/expired CMC rates
|
|
68
|
+
if (!cmc_rates[cur]) {
|
|
69
|
+
console.log('get_rate_usd rates_cmc %s does not exist', cur)
|
|
70
|
+
} else if (cmc_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
71
|
+
// some currencies like USDT are updating slow
|
|
72
|
+
console.log('get_rate_usd rates_cmc %s expired', cur)
|
|
73
|
+
}
|
|
74
|
+
return _.get(cmc_rates, [cur, 'USD'], 0)
|
|
45
75
|
}
|
|
46
76
|
get_depth(rates, cmc_rates, percentages) {
|
|
47
77
|
let depth = {}
|
|
@@ -54,11 +84,12 @@ module.exports = class Account {
|
|
|
54
84
|
continue
|
|
55
85
|
}
|
|
56
86
|
let mid = (asks[0][0] + bids[0][0]) / 2
|
|
87
|
+
let quote_cur_rate = this.get_rate_usd(quote_cur, cmc_rates)
|
|
57
88
|
for (let percentage of percentages) {
|
|
58
89
|
let ask_depth = utils.price_position(asks, mid * (1 + percentage)).sum
|
|
59
90
|
let bid_depth = utils.price_position(bids, mid / (1 + percentage)).sum
|
|
60
|
-
let ask_depth_in_usd = ask_depth *
|
|
61
|
-
let bid_depth_in_usd = bid_depth *
|
|
91
|
+
let ask_depth_in_usd = ask_depth * quote_cur_rate
|
|
92
|
+
let bid_depth_in_usd = bid_depth * quote_cur_rate
|
|
62
93
|
_.set(depth, [exchange, pair, 'ask', percentage], '$' + ask_depth_in_usd.toFixed(2))
|
|
63
94
|
_.set(depth, [exchange, pair, 'bid', percentage], '$' + bid_depth_in_usd.toFixed(2))
|
|
64
95
|
}
|
|
@@ -127,23 +158,8 @@ module.exports = class Account {
|
|
|
127
158
|
}
|
|
128
159
|
for (let cur in exchange_position[exchange]) {
|
|
129
160
|
let position = exchange_position[exchange][cur].amount
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
} else if (_.includes(['KRW'], cur)) {
|
|
133
|
-
profit.USD += position * this.forex_rates['KRWUSD']
|
|
134
|
-
} else if (_.includes(['HKD'], cur)) {
|
|
135
|
-
profit.USD += position * this.forex_rates['HKDUSD']
|
|
136
|
-
} else if (_.includes(['CNYT'], cur)) {
|
|
137
|
-
profit.USD += position * this.forex_rates['CNYUSD']
|
|
138
|
-
} else {
|
|
139
|
-
if (!cmc_rates[cur]) {
|
|
140
|
-
console.log('get_exchange_profit rates_cmc %s does not exist', cur)
|
|
141
|
-
} else if (cmc_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
142
|
-
// some currencies like USDT are updating slow
|
|
143
|
-
console.log('get_exchange_profit rates_cmc %s expired', cur)
|
|
144
|
-
}
|
|
145
|
-
profit.USD += position * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
146
|
-
}
|
|
161
|
+
let rate = this.get_rate_usd(cur, cmc_rates)
|
|
162
|
+
profit.USD += position * rate
|
|
147
163
|
}
|
|
148
164
|
_.set(exchange_profit, [exchange], profit)
|
|
149
165
|
}
|
|
@@ -164,19 +180,11 @@ module.exports = class Account {
|
|
|
164
180
|
for (let exchange in balances) {
|
|
165
181
|
let total_in_USD = 0
|
|
166
182
|
for (let cur in balances[exchange].total) {
|
|
167
|
-
|
|
168
|
-
total_in_USD += balances[exchange].total[cur] * 1
|
|
169
|
-
} else {
|
|
170
|
-
total_in_USD += balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
171
|
-
}
|
|
183
|
+
total_in_USD += balances[exchange].total[cur] * this.get_rate_usd(cur, cmc_rates)
|
|
172
184
|
}
|
|
173
185
|
for (let cur in balances[exchange].total) {
|
|
174
|
-
let
|
|
175
|
-
|
|
176
|
-
percentage = (balances[exchange].total[cur] * 1) / total_in_USD
|
|
177
|
-
} else {
|
|
178
|
-
percentage = (balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0)) / total_in_USD
|
|
179
|
-
}
|
|
186
|
+
let rate = this.get_rate_usd(cur, cmc_rates)
|
|
187
|
+
let percentage = (balances[exchange].total[cur] * rate) / total_in_USD
|
|
180
188
|
if (percentage > DISTRIBUTION_MIN_BENCHMARK) {
|
|
181
189
|
_.set(exchange_distribution, [exchange, cur], (percentage * 100).toPrecision(3) + '%')
|
|
182
190
|
}
|
|
@@ -189,21 +197,13 @@ module.exports = class Account {
|
|
|
189
197
|
let total_in_USD = 0
|
|
190
198
|
for (let exchange in balances) {
|
|
191
199
|
for (let cur in balances[exchange].total) {
|
|
192
|
-
|
|
193
|
-
total_in_USD += balances[exchange].total[cur] * 1
|
|
194
|
-
} else {
|
|
195
|
-
total_in_USD += balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
196
|
-
}
|
|
200
|
+
total_in_USD += balances[exchange].total[cur] * this.get_rate_usd(cur, cmc_rates)
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
for (let exchange in balances) {
|
|
200
204
|
for (let cur in balances[exchange].total) {
|
|
201
|
-
let
|
|
202
|
-
|
|
203
|
-
percentage = (balances[exchange].total[cur] * 1) / total_in_USD
|
|
204
|
-
} else {
|
|
205
|
-
percentage = (balances[exchange].total[cur] * _.get(cmc_rates, [cur, 'USD'], 0)) / total_in_USD
|
|
206
|
-
}
|
|
205
|
+
let rate = this.get_rate_usd(cur, cmc_rates)
|
|
206
|
+
let percentage = (balances[exchange].total[cur] * rate) / total_in_USD
|
|
207
207
|
if (percentage > DISTRIBUTION_MIN_BENCHMARK) {
|
|
208
208
|
_.set(total_distribution, [cur, exchange], (percentage * 100).toPrecision(3) + '%')
|
|
209
209
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.262",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@icgio/icg-exchanges": "^1.32.136",
|
|
21
|
-
"@icgio/icg-utils": "^1.9.
|
|
21
|
+
"@icgio/icg-utils": "^1.9.42",
|
|
22
22
|
"lodash": "^4.17.20",
|
|
23
|
-
"pg": "^8.
|
|
23
|
+
"pg": "^8.17.2"
|
|
24
24
|
}
|
|
25
25
|
}
|