@icgio/icg-exchanges-wrapper 1.9.88 → 1.9.90
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 +21 -85
- package/middleware/orders.js +2 -2
- package/package.json +1 -1
package/middleware/account.js
CHANGED
|
@@ -70,14 +70,23 @@ 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
|
+
}
|
|
84
|
+
console.log(type, exchange_assets_balances, balances)
|
|
76
85
|
let exchange_position = {}
|
|
77
86
|
for (let exchange in exchange_assets_balances) {
|
|
78
87
|
for (let cur in exchange_assets_balances[exchange]) {
|
|
79
88
|
if (!_.get(balances, [exchange, 'total'])) {
|
|
80
|
-
console.error('
|
|
89
|
+
console.error('get_exchange_position error: ', exchange, balances[exchange])
|
|
81
90
|
}
|
|
82
91
|
if (_.get(balances, [exchange, 'total', cur]) > 0) {
|
|
83
92
|
let diff = balances[exchange].total[cur] - exchange_assets_balances[exchange][cur]
|
|
@@ -88,8 +97,8 @@ module.exports = class Account {
|
|
|
88
97
|
}
|
|
89
98
|
return exchange_position
|
|
90
99
|
}
|
|
91
|
-
|
|
92
|
-
let exchange_position = this.
|
|
100
|
+
get_position(balances, type = 'initial') {
|
|
101
|
+
let exchange_position = this.get_exchange_position(balances, type)
|
|
93
102
|
let position = {}
|
|
94
103
|
for (let exchange in exchange_position) {
|
|
95
104
|
for (let cur in exchange_position[exchange]) {
|
|
@@ -98,13 +107,12 @@ module.exports = class Account {
|
|
|
98
107
|
_.set(position, [cur, 'percentage'], 0)
|
|
99
108
|
}
|
|
100
109
|
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
110
|
}
|
|
103
111
|
}
|
|
104
112
|
return position
|
|
105
113
|
}
|
|
106
|
-
|
|
107
|
-
let exchange_position = this.
|
|
114
|
+
get_exchange_profit(balances, cmc_rates, type = 'initial') {
|
|
115
|
+
let exchange_position = this.get_exchange_position(balances, type)
|
|
108
116
|
let exchange_profit = {}
|
|
109
117
|
for (let exchange in exchange_position) {
|
|
110
118
|
let profit = {
|
|
@@ -122,10 +130,10 @@ module.exports = class Account {
|
|
|
122
130
|
profit.USD += position / USDCNY
|
|
123
131
|
} else {
|
|
124
132
|
if (!cmc_rates[cur]) {
|
|
125
|
-
console.log('
|
|
133
|
+
console.log('get_exchange_profit rates_cmc %s does not exist', cur)
|
|
126
134
|
} else if (cmc_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
127
135
|
// some currencies like USDT are updating slow
|
|
128
|
-
console.log('
|
|
136
|
+
console.log('get_exchange_profit rates_cmc %s expired', cur)
|
|
129
137
|
}
|
|
130
138
|
profit.USD += position * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
131
139
|
}
|
|
@@ -134,80 +142,8 @@ module.exports = class Account {
|
|
|
134
142
|
}
|
|
135
143
|
return exchange_profit
|
|
136
144
|
}
|
|
137
|
-
|
|
138
|
-
let exchange_profit = this.
|
|
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)
|
|
165
|
-
let position = {}
|
|
166
|
-
for (let exchange in exchange_position) {
|
|
167
|
-
for (let cur in exchange_position[exchange]) {
|
|
168
|
-
if (!position[cur]) {
|
|
169
|
-
_.set(position, [cur, 'amount'], 0)
|
|
170
|
-
_.set(position, [cur, 'percentage'], 0)
|
|
171
|
-
}
|
|
172
|
-
position[cur].amount += exchange_position[exchange][cur].amount
|
|
173
|
-
position[cur].percentage = ((position[cur].amount / this.assets_benchmarks[cur]) * 100).toPrecision(3) + '%'
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return position
|
|
177
|
-
}
|
|
178
|
-
get_exchange_profit__benchmarks(benchmarks, cmc_rates) {
|
|
179
|
-
let exchange_position = this.get_exchange_position__benchmarks(benchmarks)
|
|
180
|
-
let exchange_profit = {}
|
|
181
|
-
for (let exchange in exchange_position) {
|
|
182
|
-
let profit = {
|
|
183
|
-
USD: 0,
|
|
184
|
-
}
|
|
185
|
-
for (let cur in exchange_position[exchange]) {
|
|
186
|
-
let position = exchange_position[exchange][cur].amount
|
|
187
|
-
if (_.includes(constants.stablecoins, cur)) {
|
|
188
|
-
profit.USD += position
|
|
189
|
-
} else if (_.includes(['KRW'], cur)) {
|
|
190
|
-
profit.USD += position / USDKRW
|
|
191
|
-
} else if (_.includes(['THB'], cur)) {
|
|
192
|
-
profit.USD += position / USDTHB
|
|
193
|
-
} else if (_.includes(['CNYT'], cur)) {
|
|
194
|
-
profit.USD += position / USDCNY
|
|
195
|
-
} else {
|
|
196
|
-
if (!cmc_rates[cur]) {
|
|
197
|
-
console.log('get_exchange_profit__benchmarks rates_cmc %s does not exist', cur)
|
|
198
|
-
} else if (cmc_rates[cur].update_time < new Date().getTime() - CMC_RATES_EXPIRY_TIMEOUT) {
|
|
199
|
-
// some currencies like USDT are updating slow
|
|
200
|
-
console.log('get_exchange_profit__benchmarks rates_cmc %s expired', cur)
|
|
201
|
-
}
|
|
202
|
-
profit.USD += position * _.get(cmc_rates, [cur, 'USD'], 0)
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
_.set(exchange_profit, [exchange], profit)
|
|
206
|
-
}
|
|
207
|
-
return exchange_profit
|
|
208
|
-
}
|
|
209
|
-
get_profit__benchmarks(benchmarks, cmc_rates) {
|
|
210
|
-
let exchange_profit = this.get_exchange_profit__benchmarks(benchmarks, cmc_rates)
|
|
145
|
+
get_profit(balances, cmc_rates, type = 'initial') {
|
|
146
|
+
let exchange_profit = this.get_exchange_profit(balances, cmc_rates, type)
|
|
211
147
|
let profit = {
|
|
212
148
|
USD: 0,
|
|
213
149
|
}
|
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
|