@icgio/icg-exchanges-wrapper 1.17.17 → 1.17.19
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 +22 -17
- package/package.json +3 -3
package/middleware/orders.js
CHANGED
|
@@ -278,7 +278,7 @@ module.exports = class Orders {
|
|
|
278
278
|
update_non_initial_from_balances(balances) {
|
|
279
279
|
this.account?.update_non_initial_from_balances(balances)
|
|
280
280
|
}
|
|
281
|
-
limit_trade(exchange, pair, method, price, amount, id = uuid(), order_type = '', limiter_on = true, api_key_index, order_options = {}) {
|
|
281
|
+
limit_trade(exchange, pair, method, price, amount, id = uuid(), order_type = '', limiter_on = true, api_key_index, order_options = {}, decision_context) {
|
|
282
282
|
price = round_price(exchange, pair, price)
|
|
283
283
|
amount = round_amount(exchange, pair, amount)
|
|
284
284
|
// console.log('%s %s %s %s %s %s at %s', limiter_on, order_type, exchange, pair, method, amount, price)
|
|
@@ -298,8 +298,9 @@ module.exports = class Orders {
|
|
|
298
298
|
f_amount: 0,
|
|
299
299
|
f_percentage: 0,
|
|
300
300
|
t_amount: amount,
|
|
301
|
-
open_time:
|
|
301
|
+
open_time: Date.now(),
|
|
302
302
|
close_time: null,
|
|
303
|
+
decision_context,
|
|
303
304
|
},
|
|
304
305
|
order_type + ' init',
|
|
305
306
|
)
|
|
@@ -331,7 +332,9 @@ module.exports = class Orders {
|
|
|
331
332
|
if (api_key_index) {
|
|
332
333
|
this.Exchanges[exchange].key_index = api_key_index
|
|
333
334
|
}
|
|
335
|
+
const t_order_sent = process.hrtime()
|
|
334
336
|
limit_trade((res) => {
|
|
337
|
+
const t_ack_recv = process.hrtime()
|
|
335
338
|
if (res.success) {
|
|
336
339
|
let order_id = res.body
|
|
337
340
|
this.delete_order_info(exchange, pair, method, id, order_type + ' n-filled')
|
|
@@ -351,8 +354,10 @@ module.exports = class Orders {
|
|
|
351
354
|
f_amount: 0,
|
|
352
355
|
f_percentage: 0,
|
|
353
356
|
t_amount: amount,
|
|
354
|
-
open_time:
|
|
357
|
+
open_time: Date.now(),
|
|
355
358
|
close_time: null,
|
|
359
|
+
t_order_sent,
|
|
360
|
+
t_ack_recv,
|
|
356
361
|
},
|
|
357
362
|
order_type + ' n-filled',
|
|
358
363
|
)
|
|
@@ -401,7 +406,7 @@ module.exports = class Orders {
|
|
|
401
406
|
order.order_id,
|
|
402
407
|
{
|
|
403
408
|
status: 'CANCELED',
|
|
404
|
-
close_time:
|
|
409
|
+
close_time: Date.now(),
|
|
405
410
|
},
|
|
406
411
|
order.order_type + ' canceled',
|
|
407
412
|
)
|
|
@@ -420,7 +425,7 @@ module.exports = class Orders {
|
|
|
420
425
|
amount: 0,
|
|
421
426
|
f_amount: order.amount,
|
|
422
427
|
f_percentage: 1,
|
|
423
|
-
close_time:
|
|
428
|
+
close_time: Date.now(),
|
|
424
429
|
},
|
|
425
430
|
order.order_type + ' cannot-be-canceled',
|
|
426
431
|
)
|
|
@@ -552,7 +557,7 @@ module.exports = class Orders {
|
|
|
552
557
|
amount: 0,
|
|
553
558
|
f_amount: trade_amount,
|
|
554
559
|
f_percentage: trade_amount / order_info.t_amount,
|
|
555
|
-
close_time: trade.close_time ||
|
|
560
|
+
close_time: trade.close_time || Date.now(),
|
|
556
561
|
fees: trade.fees,
|
|
557
562
|
},
|
|
558
563
|
order_info.order_type + ' canceled-order-filled(-more)',
|
|
@@ -592,7 +597,7 @@ module.exports = class Orders {
|
|
|
592
597
|
amount: order_info.t_amount - trade_amount,
|
|
593
598
|
f_amount: trade.amount,
|
|
594
599
|
f_percentage: trade_amount / order_info.t_amount,
|
|
595
|
-
close_time: trade.close_time ||
|
|
600
|
+
close_time: trade.close_time || Date.now(),
|
|
596
601
|
fees: trade.fees,
|
|
597
602
|
},
|
|
598
603
|
order_info.order_type + ' order-f-filled-1',
|
|
@@ -678,7 +683,7 @@ module.exports = class Orders {
|
|
|
678
683
|
amount: 0,
|
|
679
684
|
f_amount: order_info_order.t_amount,
|
|
680
685
|
f_percentage: 1,
|
|
681
|
-
close_time:
|
|
686
|
+
close_time: Date.now(),
|
|
682
687
|
},
|
|
683
688
|
order_info_order.order_type + ' order-f-filled-2',
|
|
684
689
|
)
|
|
@@ -713,7 +718,7 @@ module.exports = class Orders {
|
|
|
713
718
|
amount: order.amount,
|
|
714
719
|
f_amount: order_f_amount,
|
|
715
720
|
f_percentage: order_f_amount / order_info.t_amount,
|
|
716
|
-
close_time: order.close_time ||
|
|
721
|
+
close_time: order.close_time || Date.now(),
|
|
717
722
|
},
|
|
718
723
|
order_info.order_type + ' order-f-filled-3',
|
|
719
724
|
)
|
|
@@ -767,7 +772,7 @@ module.exports = class Orders {
|
|
|
767
772
|
amount: order.amount,
|
|
768
773
|
f_amount: 0,
|
|
769
774
|
t_amount: order.amount,
|
|
770
|
-
open_time: order.open_time ||
|
|
775
|
+
open_time: order.open_time || Date.now(),
|
|
771
776
|
close_time: null,
|
|
772
777
|
},
|
|
773
778
|
init_order.order_type + ' init-order-opened',
|
|
@@ -788,7 +793,7 @@ module.exports = class Orders {
|
|
|
788
793
|
order_info.order_id,
|
|
789
794
|
{
|
|
790
795
|
status: 'CANCELED',
|
|
791
|
-
close_time:
|
|
796
|
+
close_time: Date.now(),
|
|
792
797
|
},
|
|
793
798
|
(order_info.order_type || '') + ' canceling-canceled-from-open-orders',
|
|
794
799
|
)
|
|
@@ -822,7 +827,6 @@ module.exports = class Orders {
|
|
|
822
827
|
}
|
|
823
828
|
|
|
824
829
|
const order = this.order_info[exchange][pair][type][order_id]
|
|
825
|
-
order.last_update_ts = Date.now()
|
|
826
830
|
|
|
827
831
|
const new_status = order.status
|
|
828
832
|
if (old_status !== new_status) {
|
|
@@ -1331,7 +1335,7 @@ module.exports = class Orders {
|
|
|
1331
1335
|
for (let order_id in order_info[type]) {
|
|
1332
1336
|
let { open_time } = order_info[type][order_id]
|
|
1333
1337
|
// console.log(order_id, open_time, open_time < new Date() - 30 * 60 * 1000)
|
|
1334
|
-
if (open_time <
|
|
1338
|
+
if (open_time < Date.now() - QUERY_ORDER_TIME_IN_MS) {
|
|
1335
1339
|
// console.log('query_order_maker_1: %s %s %s', exchange, pair, order_id)
|
|
1336
1340
|
Exchanges[exchange].query_order(pair, order_id, (res) => {
|
|
1337
1341
|
count++
|
|
@@ -1409,12 +1413,13 @@ module.exports = class Orders {
|
|
|
1409
1413
|
let { asks, bids } = res.body
|
|
1410
1414
|
asks = asks.slice(0, RATES_LENGTH_MAX)
|
|
1411
1415
|
bids = bids.slice(0, RATES_LENGTH_MAX)
|
|
1412
|
-
_.
|
|
1416
|
+
const _ts = _.get(this.Exchanges, [exchange, 'ws', 'market', 'ts_dict', pair]) || _.get(this.ExchangesRatesOnly, [exchange, 'ws', 'market', 'ts_dict', pair])
|
|
1417
|
+
_.set(this.rates, [exchange, pair], { asks, bids, _ts })
|
|
1413
1418
|
/*
|
|
1414
1419
|
* throttle to 20ms
|
|
1415
1420
|
*/
|
|
1416
1421
|
throttled_process_rates()
|
|
1417
|
-
} else if (_.get(this.rates, [exchange, pair, '
|
|
1422
|
+
} else if (_.get(this.rates, [exchange, pair, '_ts', 'received_ts'], 0) < Date.now() - this.interval_dict[exchange].rates) {
|
|
1418
1423
|
console.log('%s %s rates expired: %j', exchange, pair, res)
|
|
1419
1424
|
if (this.rates[exchange]) delete this.rates[exchange][pair]
|
|
1420
1425
|
this.rates_observable.notify()
|
|
@@ -1523,13 +1528,13 @@ module.exports = class Orders {
|
|
|
1523
1528
|
for (let exchange in exchange_pairs) {
|
|
1524
1529
|
for (let pair of exchange_pairs[exchange]) {
|
|
1525
1530
|
if (Exchanges[exchange].ohlcv) {
|
|
1526
|
-
const ohlcv_from_timetamp = new Date().floorHours(1).
|
|
1531
|
+
const ohlcv_from_timetamp = new Date().floorHours(1).getTime() - OHLCV_DEFAULT_PAST_HOURS * 3_600_000
|
|
1527
1532
|
const ohlcv_to_timestamp = new Date().floorHours(1).getTime()
|
|
1528
1533
|
Exchanges[exchange].ohlcv(pair, ohlcv_from_timetamp, ohlcv_to_timestamp, (res) => {
|
|
1529
1534
|
ohlcv_handler(exchange, pair, res)
|
|
1530
1535
|
})
|
|
1531
1536
|
setInterval(() => {
|
|
1532
|
-
const ohlcv_from_timetamp = new Date().floorHours(1).
|
|
1537
|
+
const ohlcv_from_timetamp = new Date().floorHours(1).getTime() - OHLCV_DEFAULT_PAST_HOURS * 3_600_000
|
|
1533
1538
|
const ohlcv_to_timestamp = new Date().floorHours(1).getTime()
|
|
1534
1539
|
Exchanges[exchange].ohlcv(pair, ohlcv_from_timetamp, ohlcv_to_timestamp, (res) => {
|
|
1535
1540
|
ohlcv_handler(exchange, pair, res)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icgio/icg-exchanges-wrapper",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.19",
|
|
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.40.
|
|
21
|
-
"@icgio/icg-utils": "^1.9.
|
|
20
|
+
"@icgio/icg-exchanges": "^1.40.43",
|
|
21
|
+
"@icgio/icg-utils": "^1.9.60",
|
|
22
22
|
"lodash": "^4.17.23",
|
|
23
23
|
"pg": "^8.17.2"
|
|
24
24
|
}
|