@icgio/icg-exchanges-wrapper 1.22.0 → 1.22.2
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 +50 -32
- package/package.json +1 -1
package/middleware/orders.js
CHANGED
|
@@ -524,24 +524,32 @@ module.exports = class Orders {
|
|
|
524
524
|
this.delete_order_info(exchange, pair, order.type, order.order_id, order.order_type + ' cancel-order-success')
|
|
525
525
|
}, this.delete_finished_orders_timeout)
|
|
526
526
|
} else if (!res.success && res.error === 'order-not-open' && original_status !== 'CANCELED') {
|
|
527
|
-
//
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
527
|
+
// Not-open ≠ filled: query the actual terminal state and book it via the standard
|
|
528
|
+
// reconciler. A failed query books CANCELED keeping known fills — never fabricate a fill.
|
|
529
|
+
this.Exchanges[exchange].query_order(pair, order.order_id, (query_res) => {
|
|
530
|
+
if (query_res.success) {
|
|
531
|
+
this.process_query_order({ [exchange]: { [pair]: { query_order: [query_res.body] } } })
|
|
532
|
+
return
|
|
533
|
+
}
|
|
534
|
+
console.error('cancel not-open, query_order failed: %s %s %s %j', exchange, pair, order.order_id, query_res)
|
|
535
|
+
this.update_order_info(
|
|
536
|
+
exchange,
|
|
537
|
+
pair,
|
|
538
|
+
order.type,
|
|
539
|
+
order.order_id,
|
|
540
|
+
{
|
|
541
|
+
status: 'CANCELED',
|
|
542
|
+
f_amount: order.f_amount || 0,
|
|
543
|
+
f_percentage: order.t_amount > 0 ? (order.f_amount || 0) / order.t_amount : 0,
|
|
544
|
+
close_time: Date.now(),
|
|
545
|
+
event_hrtime: process.hrtime(),
|
|
546
|
+
},
|
|
547
|
+
order.order_type + ' cannot-be-canceled query-failed',
|
|
548
|
+
)
|
|
549
|
+
setTimeout(() => {
|
|
550
|
+
this.delete_order_info(exchange, pair, order.type, order.order_id, order.order_type + ' cannot-be-canceled query-failed')
|
|
551
|
+
}, this.delete_finished_orders_timeout)
|
|
552
|
+
})
|
|
545
553
|
} else {
|
|
546
554
|
console.error('cancel order:', exchange, pair, order, res)
|
|
547
555
|
}
|
|
@@ -946,24 +954,34 @@ module.exports = class Orders {
|
|
|
946
954
|
}
|
|
947
955
|
})
|
|
948
956
|
|
|
949
|
-
// If CANCELING orders are no longer in open_orders, infer they are canceled
|
|
957
|
+
// If CANCELING orders are no longer in open_orders, infer they are canceled — unless
|
|
958
|
+
// trades already show the order effectively filled: absence from the book is no
|
|
959
|
+
// evidence of cancellation for a filled order (push-tier races made that booking
|
|
960
|
+
// ping-pong CANCELED -> F-FILLED through the query reconciler ~1/min on busy venues).
|
|
950
961
|
const open_orders_ids_set = new Set(open_orders[exchange][pair].open_orders.map((o) => o.order_id))
|
|
951
962
|
this.get_order_info_status_all(exchange, pair, 'both', 'CANCELING').map((order_info) => {
|
|
952
963
|
if (order_info.order_id && !open_orders_ids_set.has(order_info.order_id)) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
{
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
964
|
+
const swept_f_amount = round_amount(exchange, pair, order_info.f_amount || 0)
|
|
965
|
+
const swept_t_amount = round_amount(exchange, pair, order_info.t_amount || 0)
|
|
966
|
+
const effectively_filled = swept_t_amount > 0 && swept_f_amount / swept_t_amount > this.f_filled_threshold
|
|
967
|
+
const note = (order_info.order_type || '') + (effectively_filled ? ' canceling-filled-from-open-orders' : ' canceling-canceled-from-open-orders')
|
|
968
|
+
const update_dict = effectively_filled
|
|
969
|
+
? {
|
|
970
|
+
status: 'F-FILLED',
|
|
971
|
+
amount: 0,
|
|
972
|
+
f_amount: swept_f_amount,
|
|
973
|
+
f_percentage: swept_f_amount / swept_t_amount,
|
|
974
|
+
close_time: Date.now(),
|
|
975
|
+
event_hrtime: process.hrtime(),
|
|
976
|
+
}
|
|
977
|
+
: {
|
|
978
|
+
status: 'CANCELED',
|
|
979
|
+
close_time: Date.now(),
|
|
980
|
+
event_hrtime: process.hrtime(),
|
|
981
|
+
}
|
|
982
|
+
this.update_order_info(exchange, pair, order_info.type, order_info.order_id, update_dict, note)
|
|
965
983
|
setTimeout(() => {
|
|
966
|
-
this.delete_order_info(exchange, pair, order_info.type, order_info.order_id,
|
|
984
|
+
this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, note)
|
|
967
985
|
}, this.delete_finished_orders_timeout)
|
|
968
986
|
}
|
|
969
987
|
})
|