@icgio/icg-exchanges-wrapper 1.9.90 → 1.9.92
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 +7 -3
- package/middleware/orders.js +9 -60
- package/package.json +1 -1
package/middleware/account.js
CHANGED
|
@@ -25,7 +25,7 @@ module.exports = class Account {
|
|
|
25
25
|
for (let cur in initial_balances[exchange].total) {
|
|
26
26
|
if (initial_balances[exchange].total[cur] > 0) {
|
|
27
27
|
_.set(this.initial_exchange_assets_balances, [exchange, cur], initial_balances[exchange].total[cur])
|
|
28
|
-
_.set(this.initial_assets_balances, cur, _.get(this.initial_assets_balances, cur, 0) + initial_balances[exchange].total[cur])
|
|
28
|
+
_.set(this.initial_assets_balances, cur, _.get(this.initial_assets_balances, [cur], 0) + initial_balances[exchange].total[cur])
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -37,12 +37,14 @@ module.exports = class Account {
|
|
|
37
37
|
this.raw_assets_benchmarks = {}
|
|
38
38
|
for (let exchange in raw_benchmarks) {
|
|
39
39
|
for (let cur in raw_benchmarks[exchange]) {
|
|
40
|
-
_.set(this.raw_exchange_assets_benchmarks, [exchange, cur], raw_benchmarks[exchange])
|
|
41
|
-
_.set(this.raw_assets_benchmarks, cur, _.get(this.raw_assets_benchmarks, cur, 0) + raw_benchmarks[exchange])
|
|
40
|
+
_.set(this.raw_exchange_assets_benchmarks, [exchange, cur], raw_benchmarks[exchange][cur])
|
|
41
|
+
_.set(this.raw_assets_benchmarks, cur, _.get(this.raw_assets_benchmarks, [cur], 0) + raw_benchmarks[exchange][cur])
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
this.exchange_assets_benchmarks = _.cloneDeep(this.raw_exchange_assets_benchmarks)
|
|
45
45
|
this.assets_benchmarks = _.cloneDeep(this.raw_assets_benchmarks)
|
|
46
|
+
|
|
47
|
+
console.log('exchange_assets_benchmarks', this.exchange_assets_benchmarks)
|
|
46
48
|
}
|
|
47
49
|
get_depth(rates, cmc_rates, percentages) {
|
|
48
50
|
let depth = {}
|
|
@@ -81,7 +83,9 @@ module.exports = class Account {
|
|
|
81
83
|
} else {
|
|
82
84
|
console.error('get_exchange_position type incorrect:', type)
|
|
83
85
|
}
|
|
86
|
+
|
|
84
87
|
console.log(type, exchange_assets_balances, balances)
|
|
88
|
+
|
|
85
89
|
let exchange_position = {}
|
|
86
90
|
for (let exchange in exchange_assets_balances) {
|
|
87
91
|
for (let cur in exchange_assets_balances[exchange]) {
|
package/middleware/orders.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
|
|
3
3
|
const { v4: uuid } = require('uuid')
|
|
4
|
-
const Influx = require('influx')
|
|
5
4
|
|
|
6
5
|
const icg_exchanges = require('@icgio/icg-exchanges')
|
|
7
6
|
const utils = require('@icgio/icg-utils').utils
|
|
@@ -51,27 +50,26 @@ module.exports = class Orders {
|
|
|
51
50
|
this.settings = settings || {}
|
|
52
51
|
this.ws_enabled = settings.ws_enabled || false
|
|
53
52
|
this.interval_dict = settings.interval_dict || {}
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
56
|
-
this.check_init_order_opened_timeout = settings.check_init_order_opened_timeout || 5 * 1000
|
|
53
|
+
this.check_init_order_opened = true
|
|
54
|
+
this.check_init_order_opened_timeout = 5 * 1000
|
|
57
55
|
this.cancel_previous_orders = settings.cancel_previous_orders || false
|
|
58
56
|
this.cancel_range_orders = settings.cancel_range_orders || false
|
|
59
|
-
this.delete_finished_orders_timeout =
|
|
57
|
+
this.delete_finished_orders_timeout = 30 * 1000 // CANCELED or F-FILLED
|
|
60
58
|
this.interval_dict = settings.interval_dict || {}
|
|
61
59
|
this.major_exchanges = settings.major_exchanges || []
|
|
62
60
|
this.no_cancel_previous_exchanges = settings.no_cancel_previous_exchanges || []
|
|
63
61
|
this.no_cancel_range_exchanges = settings.no_cancel_range_exchanges || []
|
|
64
62
|
this.no_trades_function_exchanges = settings.no_trades_function_exchanges || []
|
|
65
|
-
this.no_trades_function_f_filled_timeout =
|
|
63
|
+
this.no_trades_function_f_filled_timeout = 30 * 1000
|
|
66
64
|
this.bad_trades_no_arb_function_exchanges = settings.bad_trades_no_arb_function_exchanges || []
|
|
67
|
-
this.buy_sell_limits_threshold =
|
|
68
|
-
this.p_filled_threshold =
|
|
69
|
-
this.f_filled_threshold =
|
|
65
|
+
this.buy_sell_limits_threshold = 0.95
|
|
66
|
+
this.p_filled_threshold = 0
|
|
67
|
+
this.f_filled_threshold = 0.99
|
|
70
68
|
this.previous_orders_canceled = false
|
|
71
69
|
this.previous_orders_canceled_exchange_pair = {}
|
|
72
70
|
this.account_init = false
|
|
73
71
|
this.cmc_curs = settings.cmc_curs || []
|
|
74
|
-
this.balance_benchmarks = settings.
|
|
72
|
+
this.balance_benchmarks = settings.balance_benchmarks || {}
|
|
75
73
|
for (let exchange in exchange_pairs) {
|
|
76
74
|
let api_key_temp = cd[exchange]['api_keys'] || cd[exchange]['api_key'],
|
|
77
75
|
secret_key_temp = cd[exchange]['secret_keys'] || cd[exchange]['secret_key'],
|
|
@@ -104,7 +102,7 @@ module.exports = class Orders {
|
|
|
104
102
|
this.interval_dict[exchange].market_history = this.interval_dict[exchange].market_history || 2 * 1000
|
|
105
103
|
}
|
|
106
104
|
}
|
|
107
|
-
;(this.balances = {}), (this.open_orders = {}), (this.trades = {}), (this.rates = {}), (this.market_history = {}), (this.
|
|
105
|
+
;(this.balances = {}), (this.open_orders = {}), (this.trades = {}), (this.rates = {}), (this.market_history = {}), (this.cmc_rates = {})
|
|
108
106
|
;(this.rates_combined_all = {}), (this.rates_combined_all_with_buy_sell_limits = {}), (this.rates_combined_major = {}), (this.rates_combined_good_with_buy_sell_limits = {})
|
|
109
107
|
this.buy_sell_limits = {}
|
|
110
108
|
this.order_info = {}
|
|
@@ -118,7 +116,6 @@ module.exports = class Orders {
|
|
|
118
116
|
trades_check: true,
|
|
119
117
|
rates_check: true,
|
|
120
118
|
market_history_check: true,
|
|
121
|
-
volumes_check: false,
|
|
122
119
|
cmc_rates_check: true,
|
|
123
120
|
}
|
|
124
121
|
this.info_log = (...args) => {
|
|
@@ -146,9 +143,6 @@ module.exports = class Orders {
|
|
|
146
143
|
if (this.enabled.market_history_check) {
|
|
147
144
|
this.check_market_history()
|
|
148
145
|
}
|
|
149
|
-
if (this.enabled.volumes_check) {
|
|
150
|
-
this.check_volumes()
|
|
151
|
-
}
|
|
152
146
|
if (this.enabled.cmc_rates_check) {
|
|
153
147
|
this.check_cmc_rates(this.cmc_curs, 'curs')
|
|
154
148
|
}
|
|
@@ -253,18 +247,6 @@ module.exports = class Orders {
|
|
|
253
247
|
clearTimeout(no_callback_timeout)
|
|
254
248
|
})
|
|
255
249
|
}
|
|
256
|
-
limit_trade_all(pair, method, price, total) {
|
|
257
|
-
if (!this.volumes[pair]) {
|
|
258
|
-
this.error_log('%s volumes do not exist')
|
|
259
|
-
return
|
|
260
|
-
}
|
|
261
|
-
let id = uuid()
|
|
262
|
-
let sum = _.sum(_.values(this.volumes[pair]))
|
|
263
|
-
for (let exchange of this.pair_exchanges[pair]) {
|
|
264
|
-
let amount = (this.volumes[pair][exchange] / sum) * total
|
|
265
|
-
this.limit_trade(exchange, pair, method, price, amount, id)
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
250
|
market_trade(exchange, pair, method, amount, id = uuid()) {
|
|
269
251
|
if (!this.rates[exchange][pair]) {
|
|
270
252
|
this.info_log('%s %s rates do not exist', exchange, pair)
|
|
@@ -274,18 +256,6 @@ module.exports = class Orders {
|
|
|
274
256
|
let { price } = utils.vol_position(input_array, amount)
|
|
275
257
|
this.limit_trade(exchange, pair, method, price, amount, id)
|
|
276
258
|
}
|
|
277
|
-
market_trade_all(pair, method, total) {
|
|
278
|
-
if (!this.rates_combined_all[pair]) {
|
|
279
|
-
this.error_log('%s rates combined do not exist', pair)
|
|
280
|
-
return
|
|
281
|
-
}
|
|
282
|
-
let type = method === 'buy' ? 'asks' : 'bids' // reverse because it is market order
|
|
283
|
-
let { price_exchange, vol_exchange } = utils.vol_position_combined(this.rates_combined_all[pair][type], total)
|
|
284
|
-
let id = uuid()
|
|
285
|
-
for (let exchange of this.pair_exchanges[pair]) {
|
|
286
|
-
if (price_exchange[exchange] && vol_exchange[exchange]) this.limit_trade(exchange, pair, method, price_exchange[exchange], vol_exchange[exchange], id)
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
259
|
cancel_order(exchange, pair, order) {
|
|
290
260
|
let original_status = order.status
|
|
291
261
|
this.update_order_info(
|
|
@@ -1143,27 +1113,6 @@ module.exports = class Orders {
|
|
|
1143
1113
|
}
|
|
1144
1114
|
get_market_history(this.Exchanges, this.exchange_pairs, this.interval_dict)
|
|
1145
1115
|
}
|
|
1146
|
-
check_volumes() {
|
|
1147
|
-
const influx_client = new Influx.InfluxDB(this.influx_url_check_volume)
|
|
1148
|
-
let check_volumes_base = () => {
|
|
1149
|
-
for (let pair in this.pair_exchanges) {
|
|
1150
|
-
for (let exchange of this.pair_exchanges[pair]) {
|
|
1151
|
-
let query_string = `SELECT sum("vol") FROM "${pair}" WHERE ("exchange" = '${_.upperFirst(exchange)}') AND time > now() - 12h`
|
|
1152
|
-
influx_client.query(query_string).then((res) => {
|
|
1153
|
-
res.map((e) => {
|
|
1154
|
-
if (e.time && e.sum) {
|
|
1155
|
-
_.set(this.volumes, [pair, exchange], e.sum)
|
|
1156
|
-
}
|
|
1157
|
-
})
|
|
1158
|
-
})
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
check_volumes_base()
|
|
1163
|
-
setInterval(() => {
|
|
1164
|
-
check_volumes_base()
|
|
1165
|
-
}, 15 * 60 * 1000)
|
|
1166
|
-
}
|
|
1167
1116
|
check_cmc_rates(data, type) {
|
|
1168
1117
|
let check_cmc_rates_base = (data) => {
|
|
1169
1118
|
get_coinmarketcap_rates(
|