@icgio/icg-exchanges-wrapper 1.22.1 → 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.
@@ -954,24 +954,34 @@ module.exports = class Orders {
954
954
  }
955
955
  })
956
956
 
957
- // 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).
958
961
  const open_orders_ids_set = new Set(open_orders[exchange][pair].open_orders.map((o) => o.order_id))
959
962
  this.get_order_info_status_all(exchange, pair, 'both', 'CANCELING').map((order_info) => {
960
963
  if (order_info.order_id && !open_orders_ids_set.has(order_info.order_id)) {
961
- this.update_order_info(
962
- exchange,
963
- pair,
964
- order_info.type,
965
- order_info.order_id,
966
- {
967
- status: 'CANCELED',
968
- close_time: Date.now(),
969
- event_hrtime: process.hrtime(),
970
- },
971
- (order_info.order_type || '') + ' canceling-canceled-from-open-orders',
972
- )
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)
973
983
  setTimeout(() => {
974
- this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, (order_info.order_type || '') + ' canceling-canceled-from-open-orders')
984
+ this.delete_order_info(exchange, pair, order_info.type, order_info.order_id, note)
975
985
  }, this.delete_finished_orders_timeout)
976
986
  }
977
987
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.22.1",
3
+ "version": "1.22.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {