@icgio/icg-exchanges-wrapper 1.9.8 → 1.9.9
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 +13 -13
- package/package.json +2 -2
package/middleware/account.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const constants = require('@icgio/icg-utils').constants
|
|
4
|
+
|
|
5
|
+
const { USDCNY, USDKRW, USDTHB } = constants.forex_rate
|
|
4
6
|
|
|
5
7
|
module.exports = class Account {
|
|
6
8
|
constructor (initial_balances) {
|
|
@@ -60,29 +62,27 @@ module.exports = class Account {
|
|
|
60
62
|
let exchange_profit = {}
|
|
61
63
|
for (let exchange in exchange_position) {
|
|
62
64
|
let profit = {
|
|
63
|
-
|
|
65
|
+
USD: 0
|
|
64
66
|
}
|
|
65
67
|
for (let cur in exchange_position[exchange]) {
|
|
66
68
|
if (!cmc_rates[cur]) {
|
|
67
69
|
// console.error('get_exchange_profit rates_cmc %s does not exist', cur)
|
|
68
70
|
continue
|
|
69
|
-
} else if (cmc_rates[cur].update_time < new Date() - 4 * 60 * 60 * 1000) { // some currencies like USDT are updating slow
|
|
71
|
+
} else if (cmc_rates[cur].update_time < new Date().getTime() - 4 * 60 * 60 * 1000) { // some currencies like USDT are updating slow
|
|
70
72
|
console.error('get_exchange_profit rates_cmc %s expired', cur)
|
|
71
73
|
continue
|
|
72
74
|
}
|
|
73
75
|
let position = exchange_position[exchange][cur].amount
|
|
74
|
-
if (cur
|
|
75
|
-
profit.
|
|
76
|
-
} else if (_.includes(['USD', 'USDT', 'USDC', 'BUSD', 'PAX', 'GUSD', 'HUSD'], cur)) {
|
|
77
|
-
profit.BTC += position / cmc_rates.BTC.USD
|
|
76
|
+
if (_.includes(constants.stablecoins, cur)) {
|
|
77
|
+
profit.USD += position
|
|
78
78
|
} else if (_.includes(['KRW'], cur)) {
|
|
79
|
-
profit.
|
|
79
|
+
profit.USD += position / USDKRW
|
|
80
80
|
} else if (_.includes(['THB'], cur)) {
|
|
81
|
-
profit.
|
|
81
|
+
profit.USD += position / USDTHB
|
|
82
82
|
} else if (_.includes(['CNYT'], cur)) {
|
|
83
|
-
profit.
|
|
83
|
+
profit.USD += position / USDCNY
|
|
84
84
|
} else {
|
|
85
|
-
profit.
|
|
85
|
+
profit.USD += position * cmc_rates[cur].USD
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
_.set(exchange_profit, [exchange], profit)
|
|
@@ -92,10 +92,10 @@ module.exports = class Account {
|
|
|
92
92
|
get_profit (balances, cmc_rates, initial=true) {
|
|
93
93
|
let exchange_profit = this.get_exchange_profit(balances, cmc_rates, initial)
|
|
94
94
|
let profit = {
|
|
95
|
-
|
|
95
|
+
USD: 0,
|
|
96
96
|
}
|
|
97
97
|
for (let exchange in exchange_profit) {
|
|
98
|
-
profit.
|
|
98
|
+
profit.USD += exchange_profit[exchange].USD
|
|
99
99
|
}
|
|
100
100
|
return profit
|
|
101
101
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@icgio/icg-exchanges": "^1.27.3",
|
|
21
21
|
"@icgio/icg-exchanges-data": "^1.6.7",
|
|
22
|
-
"@icgio/icg-utils": "^1.7.
|
|
22
|
+
"@icgio/icg-utils": "^1.7.3",
|
|
23
23
|
"influx": "^5.7.0",
|
|
24
24
|
"lodash": "^4.17.20",
|
|
25
25
|
"needle": "^2.6.0",
|