@icgio/icg-exchanges-wrapper 1.9.114 → 1.9.115
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/orders.js +110 -10
- package/package.json +3 -3
package/middleware/orders.js
CHANGED
|
@@ -35,6 +35,7 @@ const MINIMUM_LIMITS = {
|
|
|
35
35
|
private_interval_concurrent: 3000,
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
const PROCESS_INTERVAL = 1000
|
|
38
39
|
const RATES_LENGTH_MAX = 100
|
|
39
40
|
const RATES_LENGTH_DEFAULT = 50
|
|
40
41
|
const MARKET_HISTORY_DEFAULT_TIME = 10 * 60 * 1000
|
|
@@ -98,6 +99,7 @@ module.exports = class Orders {
|
|
|
98
99
|
positions: 10 * 1000,
|
|
99
100
|
open_orders: 10 * 1000,
|
|
100
101
|
trades: 10 * 1000,
|
|
102
|
+
query_order: 10 * 1000,
|
|
101
103
|
rates: 1 * 1000,
|
|
102
104
|
market_history: 2 * 1000,
|
|
103
105
|
}
|
|
@@ -106,6 +108,7 @@ module.exports = class Orders {
|
|
|
106
108
|
this.interval_dict[exchange].positions = this.interval_dict[exchange].positions || 10 * 1000
|
|
107
109
|
this.interval_dict[exchange].open_orders = this.interval_dict[exchange].open_orders || 10 * 1000
|
|
108
110
|
this.interval_dict[exchange].trades = this.interval_dict[exchange].trades || 10 * 1000
|
|
111
|
+
this.interval_dict[exchange].query_order = this.interval_dict[exchange].query_order || 10 * 1000
|
|
109
112
|
this.interval_dict[exchange].rates = this.interval_dict[exchange].rates || 1 * 1000
|
|
110
113
|
this.interval_dict[exchange].market_history = this.interval_dict[exchange].market_history || 2 * 1000
|
|
111
114
|
}
|
|
@@ -113,11 +116,18 @@ module.exports = class Orders {
|
|
|
113
116
|
for (let exchange in this.exchange_basecur_curs_rates_only) {
|
|
114
117
|
this.ExchangesRatesOnly[exchange] = new icg_exchanges[_.upperFirst(exchange)]('', '', STANDARD_LIMITS)
|
|
115
118
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
this.balances = {}
|
|
120
|
+
this.positions = {}
|
|
121
|
+
this.open_orders = {}
|
|
122
|
+
this.trades = {}
|
|
123
|
+
this.query_order = {}
|
|
124
|
+
this.rates = {}
|
|
125
|
+
this.market_history = {}
|
|
126
|
+
this.cmc_rates = {}
|
|
127
|
+
this.rates_combined_all = {}
|
|
128
|
+
this.rates_combined_all_with_buy_sell_limits_against_reserve_balance = {}
|
|
129
|
+
this.rates_combined_major = {}
|
|
130
|
+
this.rates_combined_good_with_buy_sell_limits_against_reserve_balance = {}
|
|
121
131
|
this.buy_sell_limits_against_reserve_balance = {}
|
|
122
132
|
this.order_info = {}
|
|
123
133
|
this.order_info_status = {}
|
|
@@ -128,6 +138,7 @@ module.exports = class Orders {
|
|
|
128
138
|
positions_check: false,
|
|
129
139
|
open_orders_check: true,
|
|
130
140
|
trades_check: true,
|
|
141
|
+
query_order_check: true,
|
|
131
142
|
rates_check: true,
|
|
132
143
|
market_history_check: true,
|
|
133
144
|
cmc_rates_check: true,
|
|
@@ -151,6 +162,9 @@ module.exports = class Orders {
|
|
|
151
162
|
this.trades_amount_past_hour = {}
|
|
152
163
|
this.check_trades()
|
|
153
164
|
}
|
|
165
|
+
if (this.enabled.query_order_check) {
|
|
166
|
+
this.check_query_order()
|
|
167
|
+
}
|
|
154
168
|
if (this.enabled.rates_check) {
|
|
155
169
|
this.check_rates()
|
|
156
170
|
}
|
|
@@ -162,8 +176,14 @@ module.exports = class Orders {
|
|
|
162
176
|
}
|
|
163
177
|
if (this.enabled.balances_check && this.enabled.open_orders_check && this.enabled.trades_check) {
|
|
164
178
|
setInterval(() => {
|
|
165
|
-
this.
|
|
166
|
-
|
|
179
|
+
// this.process_trades(this.trades)
|
|
180
|
+
this.process_open_orders(this.open_orders)
|
|
181
|
+
}, PROCESS_INTERVAL)
|
|
182
|
+
}
|
|
183
|
+
if (this.enabled.query_order_check) {
|
|
184
|
+
setInterval(() => {
|
|
185
|
+
this.process_query_order(this.query_order)
|
|
186
|
+
}, PROCESS_INTERVAL)
|
|
167
187
|
}
|
|
168
188
|
this.ws_market_first_time = {}
|
|
169
189
|
}
|
|
@@ -369,7 +389,7 @@ module.exports = class Orders {
|
|
|
369
389
|
get_order_info_status_by_order_type(exchange, pair, type, status, order_type) {
|
|
370
390
|
return this.get_order_info_status_all(exchange, pair, type, status).filter((o) => o.order_type === order_type)
|
|
371
391
|
}
|
|
372
|
-
|
|
392
|
+
process_trades(trades) {
|
|
373
393
|
for (let exchange in trades) {
|
|
374
394
|
for (let pair in trades[exchange]) {
|
|
375
395
|
trades[exchange][pair].trades.map((trade) => {
|
|
@@ -463,6 +483,29 @@ module.exports = class Orders {
|
|
|
463
483
|
})
|
|
464
484
|
}
|
|
465
485
|
}
|
|
486
|
+
}
|
|
487
|
+
process_query_order(query_order) {
|
|
488
|
+
let trades = {}
|
|
489
|
+
for (let exchange in query_order) {
|
|
490
|
+
for (let pair in query_order[exchange]) {
|
|
491
|
+
let temp = query_order[exchange][pair].query_order
|
|
492
|
+
.filter((o) => _.includes(['F-FILLED', 'P-FILLED'], o.status))
|
|
493
|
+
.map((o) => {
|
|
494
|
+
return {
|
|
495
|
+
order_id: o.order_id,
|
|
496
|
+
pair: o.pair,
|
|
497
|
+
type: o.type,
|
|
498
|
+
price: o.price,
|
|
499
|
+
amount: o.f_amount,
|
|
500
|
+
total: o.price * o.f_amount,
|
|
501
|
+
}
|
|
502
|
+
})
|
|
503
|
+
_.set(trades, [exchange, pair, 'trades'], temp)
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
this.process_trades(trades)
|
|
507
|
+
}
|
|
508
|
+
process_open_orders(open_orders) {
|
|
466
509
|
for (let exchange of this.no_trades_function_exchanges) {
|
|
467
510
|
for (let pair in _.get(this.order_info, [exchange], {})) {
|
|
468
511
|
for (let type in _.get(this.order_info, [exchange, pair], {})) {
|
|
@@ -851,6 +894,7 @@ module.exports = class Orders {
|
|
|
851
894
|
get_open_orders_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
|
|
852
895
|
}
|
|
853
896
|
check_trades() {
|
|
897
|
+
const ONE_HOUR_IN_MS = 60 * 60 * 1000
|
|
854
898
|
let trades_handler = (exchange, pair, res) => {
|
|
855
899
|
if (res.success) {
|
|
856
900
|
_.set(this.trades, [exchange, pair], { trades: res.body, update_time: new Date() })
|
|
@@ -858,7 +902,7 @@ module.exports = class Orders {
|
|
|
858
902
|
this.trades_amount_past_hour,
|
|
859
903
|
[exchange, pair],
|
|
860
904
|
_.sumBy(
|
|
861
|
-
res.body.filter((t) => t.close_time > new Date().getTime() -
|
|
905
|
+
res.body.filter((t) => t.close_time > new Date().getTime() - ONE_HOUR_IN_MS || t.open_time > new Date().getTime() - ONE_HOUR_IN_MS),
|
|
862
906
|
(t) => t.amount
|
|
863
907
|
) || 0
|
|
864
908
|
)
|
|
@@ -878,7 +922,7 @@ module.exports = class Orders {
|
|
|
878
922
|
this.trades_amount_past_hour,
|
|
879
923
|
[exchange, pair],
|
|
880
924
|
_.sumBy(
|
|
881
|
-
trades.filter((t) => t.close_time > new Date().getTime() -
|
|
925
|
+
trades.filter((t) => t.close_time > new Date().getTime() - ONE_HOUR_IN_MS || t.open_time > new Date().getTime() - ONE_HOUR_IN_MS),
|
|
882
926
|
(t) => t.amount
|
|
883
927
|
) || 0
|
|
884
928
|
)
|
|
@@ -984,6 +1028,62 @@ module.exports = class Orders {
|
|
|
984
1028
|
}
|
|
985
1029
|
get_trades_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
|
|
986
1030
|
}
|
|
1031
|
+
check_query_order() {
|
|
1032
|
+
// const QUERY_ORDER_TIME_IN_MS = 30 * 60 * 1000
|
|
1033
|
+
const QUERY_ORDER_TIME_IN_MS = 0
|
|
1034
|
+
let query_order_handler = (exchange, pair, res) => {
|
|
1035
|
+
if (res.success) {
|
|
1036
|
+
_.set(this.query_order, [exchange, pair], { query_order: res.body, update_time: new Date() })
|
|
1037
|
+
} else if (_.get(this.query_order, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].query_order) {
|
|
1038
|
+
this.info_log('%s %s query_order expired: %j', exchange, pair, res)
|
|
1039
|
+
this.query_order[exchange] = _.omit(this.query_order[exchange], [pair])
|
|
1040
|
+
} else if (res.error !== 'opening') {
|
|
1041
|
+
this.error_log('%s %s query_order: %j', exchange, pair, res)
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
let get_query_order_all = (Exchanges, exchange_pairs, interval_dict) => {
|
|
1045
|
+
let query_order = (exchange, pair) => {
|
|
1046
|
+
let order_info = _.get(this.order_info, [exchange, pair], {})
|
|
1047
|
+
let timeout = setTimeout(() => {
|
|
1048
|
+
query_order(exchange, pair)
|
|
1049
|
+
}, interval_dict[exchange].query_order)
|
|
1050
|
+
let order_number = _.keys(order_info['sell']).length + _.keys(order_info['buy']).length,
|
|
1051
|
+
count = 0,
|
|
1052
|
+
result = []
|
|
1053
|
+
for (let type in order_info) {
|
|
1054
|
+
for (let order_id in order_info[type]) {
|
|
1055
|
+
let { open_time } = order_info[type][order_id]
|
|
1056
|
+
// console.log(order_id, open_time, open_time < new Date() - 30 * 60 * 1000)
|
|
1057
|
+
if (open_time < new Date() - QUERY_ORDER_TIME_IN_MS) {
|
|
1058
|
+
Exchanges[exchange].query_order(pair, order_id, (res) => {
|
|
1059
|
+
count++
|
|
1060
|
+
if (res.success) {
|
|
1061
|
+
result.push(res.body)
|
|
1062
|
+
}
|
|
1063
|
+
if (count === order_number) {
|
|
1064
|
+
query_order_handler(exchange, pair, { success: true, body: result })
|
|
1065
|
+
clearTimeout(timeout)
|
|
1066
|
+
setTimeout(() => {
|
|
1067
|
+
query_order(exchange, pair)
|
|
1068
|
+
}, interval_dict[exchange].query_order)
|
|
1069
|
+
}
|
|
1070
|
+
})
|
|
1071
|
+
} else {
|
|
1072
|
+
count++
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
for (let exchange in Exchanges) {
|
|
1078
|
+
if (Exchanges[exchange].query_order) {
|
|
1079
|
+
for (let pair of exchange_pairs[exchange]) {
|
|
1080
|
+
query_order(exchange, pair)
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
get_query_order_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
|
|
1086
|
+
}
|
|
987
1087
|
check_rates() {
|
|
988
1088
|
let process_rates = () => {
|
|
989
1089
|
for (let pair in this.pair_exchanges) {
|
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.115",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@icgio/icg-exchanges": "^1.27.
|
|
21
|
-
"@icgio/icg-exchanges-data": "^1.6.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.27.92",
|
|
21
|
+
"@icgio/icg-exchanges-data": "^1.6.46",
|
|
22
22
|
"@icgio/icg-utils": "^1.7.21",
|
|
23
23
|
"influx": "^5.7.0",
|
|
24
24
|
"lodash": "^4.17.20",
|