@icgio/icg-exchanges-wrapper 1.14.264 → 1.14.266
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 +22 -17
- package/package.json +3 -3
package/middleware/account.js
CHANGED
|
@@ -59,21 +59,26 @@ module.exports = class Account {
|
|
|
59
59
|
})
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
get_rate_usd(cur,
|
|
63
|
-
// Unified rate resolution: forex_rates first, then
|
|
62
|
+
get_rate_usd(cur, crypto_rates) {
|
|
63
|
+
// Unified rate resolution: forex_rates first, then crypto_rates fallback
|
|
64
64
|
if (this.forex_rates[cur]) {
|
|
65
65
|
return this.forex_rates[cur]
|
|
66
66
|
}
|
|
67
|
+
// Check if crypto_rates exists before accessing it
|
|
68
|
+
if (!crypto_rates) {
|
|
69
|
+
console.log('get_rate_usd crypto_rates is undefined for %s', cur)
|
|
70
|
+
return 0
|
|
71
|
+
}
|
|
67
72
|
// Log warnings for missing/expired CMC rates
|
|
68
|
-
if (!
|
|
73
|
+
if (!crypto_rates[cur]) {
|
|
69
74
|
console.log('get_rate_usd rates_cmc %s does not exist', cur)
|
|
70
|
-
} else if (
|
|
75
|
+
} else if (crypto_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
71
76
|
// some currencies like USDT are updating slow
|
|
72
77
|
console.log('get_rate_usd rates_cmc %s expired', cur)
|
|
73
78
|
}
|
|
74
|
-
return _.get(
|
|
79
|
+
return _.get(crypto_rates, [cur, 'USD'], 0)
|
|
75
80
|
}
|
|
76
|
-
get_depth(rates,
|
|
81
|
+
get_depth(rates, crypto_rates, percentages) {
|
|
77
82
|
let depth = {}
|
|
78
83
|
for (let exchange in rates) {
|
|
79
84
|
for (let pair in rates[exchange]) {
|
|
@@ -84,7 +89,7 @@ module.exports = class Account {
|
|
|
84
89
|
continue
|
|
85
90
|
}
|
|
86
91
|
let mid = (asks[0][0] + bids[0][0]) / 2
|
|
87
|
-
let quote_cur_rate = this.get_rate_usd(quote_cur,
|
|
92
|
+
let quote_cur_rate = this.get_rate_usd(quote_cur, crypto_rates)
|
|
88
93
|
for (let percentage of percentages) {
|
|
89
94
|
let ask_depth = utils.price_position(asks, mid * (1 + percentage)).sum
|
|
90
95
|
let bid_depth = utils.price_position(bids, mid / (1 + percentage)).sum
|
|
@@ -149,7 +154,7 @@ module.exports = class Account {
|
|
|
149
154
|
}
|
|
150
155
|
return position
|
|
151
156
|
}
|
|
152
|
-
get_exchange_profit(balances,
|
|
157
|
+
get_exchange_profit(balances, crypto_rates, type = 'initial') {
|
|
153
158
|
let exchange_position = this.get_exchange_position(balances, type)
|
|
154
159
|
let exchange_profit = {}
|
|
155
160
|
for (let exchange in exchange_position) {
|
|
@@ -158,15 +163,15 @@ module.exports = class Account {
|
|
|
158
163
|
}
|
|
159
164
|
for (let cur in exchange_position[exchange]) {
|
|
160
165
|
let position = exchange_position[exchange][cur].amount
|
|
161
|
-
let rate = this.get_rate_usd(cur,
|
|
166
|
+
let rate = this.get_rate_usd(cur, crypto_rates)
|
|
162
167
|
profit.USD += position * rate
|
|
163
168
|
}
|
|
164
169
|
_.set(exchange_profit, [exchange], profit)
|
|
165
170
|
}
|
|
166
171
|
return exchange_profit
|
|
167
172
|
}
|
|
168
|
-
get_profit(balances,
|
|
169
|
-
let exchange_profit = this.get_exchange_profit(balances,
|
|
173
|
+
get_profit(balances, crypto_rates, type = 'initial') {
|
|
174
|
+
let exchange_profit = this.get_exchange_profit(balances, crypto_rates, type)
|
|
170
175
|
let profit = {
|
|
171
176
|
USD: 0,
|
|
172
177
|
}
|
|
@@ -175,15 +180,15 @@ module.exports = class Account {
|
|
|
175
180
|
}
|
|
176
181
|
return profit
|
|
177
182
|
}
|
|
178
|
-
get_exchange_distribution(balances,
|
|
183
|
+
get_exchange_distribution(balances, crypto_rates) {
|
|
179
184
|
let exchange_distribution = {}
|
|
180
185
|
for (let exchange in balances) {
|
|
181
186
|
let total_in_USD = 0
|
|
182
187
|
for (let cur in balances[exchange].total) {
|
|
183
|
-
total_in_USD += balances[exchange].total[cur] * this.get_rate_usd(cur,
|
|
188
|
+
total_in_USD += balances[exchange].total[cur] * this.get_rate_usd(cur, crypto_rates)
|
|
184
189
|
}
|
|
185
190
|
for (let cur in balances[exchange].total) {
|
|
186
|
-
let rate = this.get_rate_usd(cur,
|
|
191
|
+
let rate = this.get_rate_usd(cur, crypto_rates)
|
|
187
192
|
let percentage = (balances[exchange].total[cur] * rate) / total_in_USD
|
|
188
193
|
if (percentage > DISTRIBUTION_MIN_BENCHMARK) {
|
|
189
194
|
_.set(exchange_distribution, [exchange, cur], (percentage * 100).toPrecision(3) + '%')
|
|
@@ -192,17 +197,17 @@ module.exports = class Account {
|
|
|
192
197
|
}
|
|
193
198
|
return exchange_distribution
|
|
194
199
|
}
|
|
195
|
-
get_total_distribution(balances,
|
|
200
|
+
get_total_distribution(balances, crypto_rates) {
|
|
196
201
|
let total_distribution = {}
|
|
197
202
|
let total_in_USD = 0
|
|
198
203
|
for (let exchange in balances) {
|
|
199
204
|
for (let cur in balances[exchange].total) {
|
|
200
|
-
total_in_USD += balances[exchange].total[cur] * this.get_rate_usd(cur,
|
|
205
|
+
total_in_USD += balances[exchange].total[cur] * this.get_rate_usd(cur, crypto_rates)
|
|
201
206
|
}
|
|
202
207
|
}
|
|
203
208
|
for (let exchange in balances) {
|
|
204
209
|
for (let cur in balances[exchange].total) {
|
|
205
|
-
let rate = this.get_rate_usd(cur,
|
|
210
|
+
let rate = this.get_rate_usd(cur, crypto_rates)
|
|
206
211
|
let percentage = (balances[exchange].total[cur] * rate) / total_in_USD
|
|
207
212
|
if (percentage > DISTRIBUTION_MIN_BENCHMARK) {
|
|
208
213
|
_.set(total_distribution, [cur, exchange], (percentage * 100).toPrecision(3) + '%')
|
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.266",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@icgio/icg-exchanges": "^1.32.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.32.137",
|
|
21
21
|
"@icgio/icg-utils": "^1.9.44",
|
|
22
|
-
"lodash": "^4.17.
|
|
22
|
+
"lodash": "^4.17.23",
|
|
23
23
|
"pg": "^8.17.2"
|
|
24
24
|
}
|
|
25
25
|
}
|