@icgio/icg-exchanges-wrapper 1.9.87 → 1.9.89
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 +20 -85
- package/middleware/orders.js +2 -2
- package/package.json +3 -3
package/middleware/account.js
CHANGED
|
@@ -70,14 +70,22 @@ module.exports = class Account {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
get_exchange_position(balances, type = 'initial') {
|
|
74
|
+
let exchange_assets_balances
|
|
75
|
+
if (type === 'initial') {
|
|
76
|
+
exchange_assets_balances = this.initial_exchange_assets_balances
|
|
77
|
+
} else if (type === 'non_initial') {
|
|
78
|
+
exchange_assets_balances = this.non_initial_exchange_assets_balances
|
|
79
|
+
} else if (type === 'benchmark') {
|
|
80
|
+
exchange_assets_balances = this.exchange_assets_benchmarks
|
|
81
|
+
} else {
|
|
82
|
+
console.error('get_exchange_position type incorrect:', type)
|
|
83
|
+
}
|
|
76
84
|
let exchange_position = {}
|
|
77
85
|
for (let exchange in exchange_assets_balances) {
|
|
78
86
|
for (let cur in exchange_assets_balances[exchange]) {
|
|
79
87
|
if (!_.get(balances, [exchange, 'total'])) {
|
|
80
|
-
console.error('
|
|
88
|
+
console.error('get_exchange_position error: ', exchange, balances[exchange])
|
|
81
89
|
}
|
|
82
90
|
if (_.get(balances, [exchange, 'total', cur]) > 0) {
|
|
83
91
|
let diff = balances[exchange].total[cur] - exchange_assets_balances[exchange][cur]
|
|
@@ -88,80 +96,8 @@ module.exports = class Account {
|
|
|
88
96
|
}
|
|
89
97
|
return exchange_position
|
|
90
98
|
}
|
|
91
|
-
|
|
92
|
-
let exchange_position = this.
|
|
93
|
-
let position = {}
|
|
94
|
-
for (let exchange in exchange_position) {
|
|
95
|
-
for (let cur in exchange_position[exchange]) {
|
|
96
|
-
if (!position[cur]) {
|
|
97
|
-
_.set(position, [cur, 'amount'], 0)
|
|
98
|
-
_.set(position, [cur, 'percentage'], 0)
|
|
99
|
-
}
|
|
100
|
-
position[cur].amount += exchange_position[exchange][cur].amount
|
|
101
|
-
position[cur].percentage = ((position[cur].amount / this.non_initial_assets_balances[cur]) * 100).toPrecision(3) + '%'
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return position
|
|
105
|
-
}
|
|
106
|
-
get_exchange_profit__balances(balances, cmc_rates, initial = true) {
|
|
107
|
-
let exchange_position = this.get_exchange_position__balances(balances, initial)
|
|
108
|
-
let exchange_profit = {}
|
|
109
|
-
for (let exchange in exchange_position) {
|
|
110
|
-
let profit = {
|
|
111
|
-
USD: 0,
|
|
112
|
-
}
|
|
113
|
-
for (let cur in exchange_position[exchange]) {
|
|
114
|
-
let position = exchange_position[exchange][cur].amount
|
|
115
|
-
if (_.includes(constants.stablecoins, cur)) {
|
|
116
|
-
profit.USD += position
|
|
117
|
-
} else if (_.includes(['KRW'], cur)) {
|
|
118
|
-
profit.USD += position / USDKRW
|
|
119
|
-
} else if (_.includes(['THB'], cur)) {
|
|
120
|
-
profit.USD += position / USDTHB
|
|
121
|
-
} else if (_.includes(['CNYT'], cur)) {
|
|
122
|
-
profit.USD += position / USDCNY
|
|
123
|
-
} else {
|
|
124
|
-
if (!cmc_rates[cur]) {
|
|
125
|
-
console.log('get_exchange_profit__balances rates_cmc %s does not exist', cur)
|
|
126
|
-
} else if (cmc_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
127
|
-
// some currencies like USDT are updating slow
|
|
128
|
-
console.log('get_exchange_profit__balances rates_cmc %s expired', cur)
|
|
129
|
-
}
|
|
130
|
-
profit.USD += position * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
_.set(exchange_profit, [exchange], profit)
|
|
134
|
-
}
|
|
135
|
-
return exchange_profit
|
|
136
|
-
}
|
|
137
|
-
get_profit__balances(balances, cmc_rates, initial = true) {
|
|
138
|
-
let exchange_profit = this.get_exchange_profit__balances(balances, cmc_rates, initial)
|
|
139
|
-
let profit = {
|
|
140
|
-
USD: 0,
|
|
141
|
-
}
|
|
142
|
-
for (let exchange in exchange_profit) {
|
|
143
|
-
profit.USD += exchange_profit[exchange].USD
|
|
144
|
-
}
|
|
145
|
-
return profit
|
|
146
|
-
}
|
|
147
|
-
// benchmarks
|
|
148
|
-
get_exchange_position__benchmarks(benchmarks) {
|
|
149
|
-
let exchange_assets_benchmarks = this.exchange_assets_benchmarks
|
|
150
|
-
let exchange_position = {}
|
|
151
|
-
for (let exchange in exchange_assets_benchmarks) {
|
|
152
|
-
for (let cur in exchange_assets_benchmarks[exchange]) {
|
|
153
|
-
if (!_.get(benchmarks, [exchange])) console.error('get_exchange_position__benchmarks error: ', exchange, benchmarks[exchange])
|
|
154
|
-
if (_.get(benchmarks, [exchange, cur])) {
|
|
155
|
-
let diff = benchmarks[exchange][cur] - exchange_assets_benchmarks[exchange][cur]
|
|
156
|
-
_.set(exchange_position, [exchange, cur, 'amount'], diff)
|
|
157
|
-
_.set(exchange_position, [exchange, cur, 'percentage'], ((diff / exchange_assets_benchmarks[exchange][cur]) * 100).toPrecision(3) + '%')
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return exchange_position
|
|
162
|
-
}
|
|
163
|
-
get_position__benchmarks(benchmarks) {
|
|
164
|
-
let exchange_position = this.get_exchange_position__benchmarks(benchmarks)
|
|
99
|
+
get_position(balances, type = 'initial') {
|
|
100
|
+
let exchange_position = this.get_exchange_position(balances, type)
|
|
165
101
|
let position = {}
|
|
166
102
|
for (let exchange in exchange_position) {
|
|
167
103
|
for (let cur in exchange_position[exchange]) {
|
|
@@ -170,13 +106,12 @@ module.exports = class Account {
|
|
|
170
106
|
_.set(position, [cur, 'percentage'], 0)
|
|
171
107
|
}
|
|
172
108
|
position[cur].amount += exchange_position[exchange][cur].amount
|
|
173
|
-
position[cur].percentage = ((position[cur].amount / this.assets_benchmarks[cur]) * 100).toPrecision(3) + '%'
|
|
174
109
|
}
|
|
175
110
|
}
|
|
176
111
|
return position
|
|
177
112
|
}
|
|
178
|
-
|
|
179
|
-
let exchange_position = this.
|
|
113
|
+
get_exchange_profit(balances, cmc_rates, type = 'initial') {
|
|
114
|
+
let exchange_position = this.get_exchange_position(balances, type)
|
|
180
115
|
let exchange_profit = {}
|
|
181
116
|
for (let exchange in exchange_position) {
|
|
182
117
|
let profit = {
|
|
@@ -194,10 +129,10 @@ module.exports = class Account {
|
|
|
194
129
|
profit.USD += position / USDCNY
|
|
195
130
|
} else {
|
|
196
131
|
if (!cmc_rates[cur]) {
|
|
197
|
-
console.log('
|
|
132
|
+
console.log('get_exchange_profit rates_cmc %s does not exist', cur)
|
|
198
133
|
} else if (cmc_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
199
134
|
// some currencies like USDT are updating slow
|
|
200
|
-
console.log('
|
|
135
|
+
console.log('get_exchange_profit rates_cmc %s expired', cur)
|
|
201
136
|
}
|
|
202
137
|
profit.USD += position * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
203
138
|
}
|
|
@@ -206,8 +141,8 @@ module.exports = class Account {
|
|
|
206
141
|
}
|
|
207
142
|
return exchange_profit
|
|
208
143
|
}
|
|
209
|
-
|
|
210
|
-
let exchange_profit = this.
|
|
144
|
+
get_profit(balances, cmc_rates, type = 'initial') {
|
|
145
|
+
let exchange_profit = this.get_exchange_profit(balances, cmc_rates, type)
|
|
211
146
|
let profit = {
|
|
212
147
|
USD: 0,
|
|
213
148
|
}
|
package/middleware/orders.js
CHANGED
|
@@ -685,7 +685,7 @@ module.exports = class Orders {
|
|
|
685
685
|
this.buy_sell_limits = _.omit(this.buy_sell_limits, [exchange])
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
|
-
function
|
|
688
|
+
function get_positions(Exchanges, interval_dict) {
|
|
689
689
|
for (let exchange in Exchanges) {
|
|
690
690
|
if (Exchanges[exchange].position_all_ws) {
|
|
691
691
|
if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
|
|
@@ -720,7 +720,7 @@ module.exports = class Orders {
|
|
|
720
720
|
}
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
|
|
723
|
+
get_positions(this.Exchanges, this.interval_dict)
|
|
724
724
|
}
|
|
725
725
|
check_open_orders() {
|
|
726
726
|
const open_orders_timeframe = 12 * 60 * 60 * 1000
|
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.89",
|
|
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.27.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.27.71",
|
|
21
21
|
"@icgio/icg-exchanges-data": "^1.6.38",
|
|
22
|
-
"@icgio/icg-utils": "^1.7.
|
|
22
|
+
"@icgio/icg-utils": "^1.7.14",
|
|
23
23
|
"influx": "^5.7.0",
|
|
24
24
|
"lodash": "^4.17.20",
|
|
25
25
|
"needle": "^2.6.0",
|