@icgio/icg-exchanges-wrapper 1.14.262 → 1.14.264
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 +36 -34
- package/package.json +2 -2
package/middleware/orders.js
CHANGED
|
@@ -4,7 +4,7 @@ const { randomUUID: uuid } = require('crypto')
|
|
|
4
4
|
|
|
5
5
|
const ICGExchanges = require('@icgio/icg-exchanges')
|
|
6
6
|
const utils = require('@icgio/icg-utils').utils
|
|
7
|
-
const {
|
|
7
|
+
const { crypto_rates: get_crypto_rates, observable: Observable } = require('@icgio/icg-utils')
|
|
8
8
|
|
|
9
9
|
const Account = require('./account.js')
|
|
10
10
|
const { ws_data_client } = require('../lib/ws-data-client.js')
|
|
@@ -180,7 +180,7 @@ module.exports = class Orders {
|
|
|
180
180
|
this.rates_observable = new Observable()
|
|
181
181
|
this.market_history = {}
|
|
182
182
|
this.ohlcv = {}
|
|
183
|
-
this.
|
|
183
|
+
this.crypto_rates = {}
|
|
184
184
|
this.rates_combined_all = {}
|
|
185
185
|
this.rates_combined_all_with_buy_sell_limits_against_reserve_balance = {}
|
|
186
186
|
this.rates_combined_major = {}
|
|
@@ -198,7 +198,7 @@ module.exports = class Orders {
|
|
|
198
198
|
rates_check: true,
|
|
199
199
|
market_history_check: true,
|
|
200
200
|
ohlcv_check: false,
|
|
201
|
-
|
|
201
|
+
crypto_rates_check: true,
|
|
202
202
|
}
|
|
203
203
|
if (this.function_enabled.balances_check) {
|
|
204
204
|
this.check_balances()
|
|
@@ -229,8 +229,8 @@ module.exports = class Orders {
|
|
|
229
229
|
if (this.function_enabled.ohlcv_check) {
|
|
230
230
|
this.check_ohlcv()
|
|
231
231
|
}
|
|
232
|
-
if (this.function_enabled.
|
|
233
|
-
this.
|
|
232
|
+
if (this.function_enabled.crypto_rates_check) {
|
|
233
|
+
this.check_crypto_rates(this.cmc_curs, 'curs_dict')
|
|
234
234
|
}
|
|
235
235
|
if (this.function_enabled.balances_check && this.function_enabled.open_orders_check && this.function_enabled.trades_check) {
|
|
236
236
|
setInterval(() => {
|
|
@@ -278,7 +278,7 @@ module.exports = class Orders {
|
|
|
278
278
|
open_time: new Date(),
|
|
279
279
|
close_time: null,
|
|
280
280
|
},
|
|
281
|
-
order_type + ' init'
|
|
281
|
+
order_type + ' init',
|
|
282
282
|
)
|
|
283
283
|
let no_callback_timeout = setTimeout(() => {
|
|
284
284
|
if (_.get(this.order_info, [exchange, pair, method, id, 'status']) === 'INIT') {
|
|
@@ -291,7 +291,7 @@ module.exports = class Orders {
|
|
|
291
291
|
{
|
|
292
292
|
status: 'N-OPENED-TIMEOUT',
|
|
293
293
|
},
|
|
294
|
-
order_type + ' n-opened-timeout-init'
|
|
294
|
+
order_type + ' n-opened-timeout-init',
|
|
295
295
|
)
|
|
296
296
|
}
|
|
297
297
|
}, NO_CALLBACK_TIMEOUT_MS)
|
|
@@ -357,7 +357,7 @@ module.exports = class Orders {
|
|
|
357
357
|
open_time: new Date(),
|
|
358
358
|
close_time: null,
|
|
359
359
|
},
|
|
360
|
-
order_type + ' n-filled'
|
|
360
|
+
order_type + ' n-filled',
|
|
361
361
|
)
|
|
362
362
|
} else if (res.error === 'amount-too-small' || res.error === 'insufficient-funds') {
|
|
363
363
|
this.delete_order_info(exchange, pair, method, id, order_type + ' limit-trade-' + res.error)
|
|
@@ -389,9 +389,9 @@ module.exports = class Orders {
|
|
|
389
389
|
{
|
|
390
390
|
status: 'CANCELING',
|
|
391
391
|
},
|
|
392
|
-
order.order_type + ' canceling'
|
|
392
|
+
order.order_type + ' canceling',
|
|
393
393
|
)
|
|
394
|
-
;(order.exchange = exchange), (order.pair = pair)
|
|
394
|
+
;((order.exchange = exchange), (order.pair = pair))
|
|
395
395
|
this.Exchanges[exchange].cancel_order_by_order(order, (res) => {
|
|
396
396
|
if (res.success || (!res.success && res.error === 'order-not-open' && original_status === 'CANCELING')) {
|
|
397
397
|
this.update_order_info(
|
|
@@ -403,7 +403,7 @@ module.exports = class Orders {
|
|
|
403
403
|
status: 'CANCELED',
|
|
404
404
|
close_time: new Date(),
|
|
405
405
|
},
|
|
406
|
-
order.order_type + ' canceled'
|
|
406
|
+
order.order_type + ' canceled',
|
|
407
407
|
)
|
|
408
408
|
setTimeout(() => {
|
|
409
409
|
this.delete_order_info(exchange, pair, order.type, order.order_id, order.order_type + ' cancel-order-success')
|
|
@@ -422,7 +422,7 @@ module.exports = class Orders {
|
|
|
422
422
|
f_percentage: 1,
|
|
423
423
|
close_time: new Date(),
|
|
424
424
|
},
|
|
425
|
-
order.order_type + ' cannot-be-canceled'
|
|
425
|
+
order.order_type + ' cannot-be-canceled',
|
|
426
426
|
)
|
|
427
427
|
setTimeout(() => {
|
|
428
428
|
this.delete_order_info(exchange, pair, order.type, order.order_id, order.order_type + ' cannot-be-canceled')
|
|
@@ -521,7 +521,7 @@ module.exports = class Orders {
|
|
|
521
521
|
close_time: trade.close_time || new Date(),
|
|
522
522
|
fees: trade.fees,
|
|
523
523
|
},
|
|
524
|
-
order_info.order_type + ' canceled-order-filled(-more)'
|
|
524
|
+
order_info.order_type + ' canceled-order-filled(-more)',
|
|
525
525
|
)
|
|
526
526
|
setTimeout(() => {
|
|
527
527
|
this.delete_order_info(exchange, pair, type, order_id, order_info.order_type + ' canceled-order-filled(-more)')
|
|
@@ -539,7 +539,7 @@ module.exports = class Orders {
|
|
|
539
539
|
f_percentage: 1,
|
|
540
540
|
fees: trade.fees,
|
|
541
541
|
},
|
|
542
|
-
order_info.order_type + ' filled-order-filled-more'
|
|
542
|
+
order_info.order_type + ' filled-order-filled-more',
|
|
543
543
|
)
|
|
544
544
|
} else if (
|
|
545
545
|
_.includes(['N-FILLED', 'P-FILLED'], order_info.status) &&
|
|
@@ -561,7 +561,7 @@ module.exports = class Orders {
|
|
|
561
561
|
close_time: trade.close_time || new Date(),
|
|
562
562
|
fees: trade.fees,
|
|
563
563
|
},
|
|
564
|
-
order_info.order_type + ' order-f-filled-1'
|
|
564
|
+
order_info.order_type + ' order-f-filled-1',
|
|
565
565
|
)
|
|
566
566
|
setTimeout(() => {
|
|
567
567
|
this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, order_info.order_type + ' order-f-filled-1')
|
|
@@ -584,7 +584,7 @@ module.exports = class Orders {
|
|
|
584
584
|
f_percentage: trade.amount / order_info.t_amount,
|
|
585
585
|
fees: trade.fees,
|
|
586
586
|
},
|
|
587
|
-
order_info.order_type + ' order-p-filled-1'
|
|
587
|
+
order_info.order_type + ' order-p-filled-1',
|
|
588
588
|
)
|
|
589
589
|
} else if (_.includes(['F-FILLED', 'P-FILLED'], order_info.status)) {
|
|
590
590
|
} else if (_.includes(['CANCELED', 'CANCELING'], order_info.status) && trade.amount === order_info.f_amount) {
|
|
@@ -646,7 +646,7 @@ module.exports = class Orders {
|
|
|
646
646
|
f_percentage: 1,
|
|
647
647
|
close_time: new Date(),
|
|
648
648
|
},
|
|
649
|
-
order_info_order.order_type + ' order-f-filled-2'
|
|
649
|
+
order_info_order.order_type + ' order-f-filled-2',
|
|
650
650
|
)
|
|
651
651
|
setTimeout(() => {
|
|
652
652
|
this.delete_order_info(exchange, pair, order_info_order.type, order_info_order.order_id, order_info_order.order_type + ' order-f-filled-2')
|
|
@@ -681,7 +681,7 @@ module.exports = class Orders {
|
|
|
681
681
|
f_percentage: order_f_amount / order_info.t_amount,
|
|
682
682
|
close_time: order.close_time || new Date(),
|
|
683
683
|
},
|
|
684
|
-
order_info.order_type + ' order-f-filled-3'
|
|
684
|
+
order_info.order_type + ' order-f-filled-3',
|
|
685
685
|
)
|
|
686
686
|
setTimeout(() => {
|
|
687
687
|
this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, order_info.order_type + ' order-f-filled-3')
|
|
@@ -703,7 +703,7 @@ module.exports = class Orders {
|
|
|
703
703
|
f_amount: order_f_amount,
|
|
704
704
|
f_percentage: order_f_amount / order_info.t_amount,
|
|
705
705
|
},
|
|
706
|
-
order_info.order_type + ' order-p-filled-2'
|
|
706
|
+
order_info.order_type + ' order-p-filled-2',
|
|
707
707
|
)
|
|
708
708
|
}
|
|
709
709
|
} else if (this.get_order_info_status_all(exchange, pair, 'both', 'INIT') && this.check_init_order_opened) {
|
|
@@ -736,7 +736,7 @@ module.exports = class Orders {
|
|
|
736
736
|
open_time: order.open_time || new Date(),
|
|
737
737
|
close_time: null,
|
|
738
738
|
},
|
|
739
|
-
init_order.order_type + ' init-order-opened'
|
|
739
|
+
init_order.order_type + ' init-order-opened',
|
|
740
740
|
)
|
|
741
741
|
}
|
|
742
742
|
})
|
|
@@ -756,7 +756,7 @@ module.exports = class Orders {
|
|
|
756
756
|
status: 'CANCELED',
|
|
757
757
|
close_time: new Date(),
|
|
758
758
|
},
|
|
759
|
-
(order_info.order_type || '') + ' canceling-canceled-from-open-orders'
|
|
759
|
+
(order_info.order_type || '') + ' canceling-canceled-from-open-orders',
|
|
760
760
|
)
|
|
761
761
|
setTimeout(() => {
|
|
762
762
|
this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, (order_info.order_type || '') + ' canceling-canceled-from-open-orders')
|
|
@@ -1105,8 +1105,8 @@ module.exports = class Orders {
|
|
|
1105
1105
|
[exchange, pair],
|
|
1106
1106
|
_.sumBy(
|
|
1107
1107
|
res.body.filter((t) => t.close_time > new Date().getTime() - ONE_HOUR_IN_MS || t.open_time > new Date().getTime() - ONE_HOUR_IN_MS),
|
|
1108
|
-
(t) => t.amount
|
|
1109
|
-
) || 0
|
|
1108
|
+
(t) => t.amount,
|
|
1109
|
+
) || 0,
|
|
1110
1110
|
)
|
|
1111
1111
|
} else if (_.get(this.trades, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].trades) {
|
|
1112
1112
|
console.log('%s %s trades expired: %j', exchange, pair, res)
|
|
@@ -1125,8 +1125,8 @@ module.exports = class Orders {
|
|
|
1125
1125
|
[exchange, pair],
|
|
1126
1126
|
_.sumBy(
|
|
1127
1127
|
trades.filter((t) => t.close_time > new Date().getTime() - ONE_HOUR_IN_MS || t.open_time > new Date().getTime() - ONE_HOUR_IN_MS),
|
|
1128
|
-
(t) => t.amount
|
|
1129
|
-
) || 0
|
|
1128
|
+
(t) => t.amount,
|
|
1129
|
+
) || 0,
|
|
1130
1130
|
)
|
|
1131
1131
|
}
|
|
1132
1132
|
} else if (res.error !== 'opening') {
|
|
@@ -1544,20 +1544,22 @@ module.exports = class Orders {
|
|
|
1544
1544
|
}
|
|
1545
1545
|
get_ohlcv(this.Exchanges, this.exchange_pairs_without_affiliates, this.interval_dict)
|
|
1546
1546
|
}
|
|
1547
|
-
|
|
1548
|
-
let
|
|
1549
|
-
|
|
1547
|
+
check_crypto_rates(data, type) {
|
|
1548
|
+
let check_crypto_rates_base = (data, type) => {
|
|
1549
|
+
get_crypto_rates(
|
|
1550
1550
|
(rates) => {
|
|
1551
|
-
this.
|
|
1551
|
+
this.crypto_rates = rates
|
|
1552
1552
|
},
|
|
1553
1553
|
data,
|
|
1554
1554
|
type,
|
|
1555
|
-
source
|
|
1556
1555
|
)
|
|
1557
1556
|
}
|
|
1558
|
-
|
|
1559
|
-
setInterval(
|
|
1560
|
-
|
|
1561
|
-
|
|
1557
|
+
check_crypto_rates_base(data, type)
|
|
1558
|
+
setInterval(
|
|
1559
|
+
() => {
|
|
1560
|
+
check_crypto_rates_base(data, type)
|
|
1561
|
+
},
|
|
1562
|
+
15 * 60 * 1000,
|
|
1563
|
+
)
|
|
1562
1564
|
}
|
|
1563
1565
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.264",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@icgio/icg-exchanges": "^1.32.136",
|
|
21
|
-
"@icgio/icg-utils": "^1.9.
|
|
21
|
+
"@icgio/icg-utils": "^1.9.44",
|
|
22
22
|
"lodash": "^4.17.20",
|
|
23
23
|
"pg": "^8.17.2"
|
|
24
24
|
}
|