@icgio/icg-exchanges-wrapper 1.21.23 → 1.21.25

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.
@@ -857,6 +857,7 @@ module.exports = class Orders {
857
857
  }
858
858
  for (let exchange in open_orders) {
859
859
  for (let pair in open_orders[exchange]) {
860
+ const init_orders = this.check_init_order_opened ? this.get_order_info_status_all(exchange, pair, 'both', 'INIT') : []
860
861
  open_orders[exchange][pair].open_orders.map((order) => {
861
862
  if (_.get(this.order_info, [exchange, pair, order.type, order.order_id])) {
862
863
  let order_info = this.order_info[exchange][pair][order.type][order.order_id]
@@ -905,8 +906,8 @@ module.exports = class Orders {
905
906
  order_info.order_type + ' order-p-filled-2',
906
907
  )
907
908
  }
908
- } else if (this.get_order_info_status_all(exchange, pair, 'both', 'INIT') && this.check_init_order_opened) {
909
- this.get_order_info_status_all(exchange, pair, 'both', 'INIT').map((init_order) => {
909
+ } else if (init_orders.length > 0) {
910
+ init_orders.forEach((init_order) => {
910
911
  let init_order_price = round_price(exchange, pair, init_order.price)
911
912
  let order_price = round_price(exchange, pair, order.price)
912
913
  let init_order_time = typeof init_order.open_time === 'number' ? init_order.open_time : new Date(init_order.open_time).getTime()
@@ -1492,8 +1493,7 @@ module.exports = class Orders {
1492
1493
  get_trades_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
1493
1494
  }
1494
1495
  check_query_order(exchange, order_types) {
1495
- // const QUERY_ORDER_TIME_IN_MS = 30 * 60 * 1000
1496
- const QUERY_ORDER_TIME_IN_MS = 0
1496
+ const QUERY_ORDER_TIME_IN_MS = 5 * 1000
1497
1497
  const types = order_types && order_types.length > 0 ? order_types : ['maker_1']
1498
1498
  let query_order_handler = (exchange, pair, res) => {
1499
1499
  if (res.success) {
@@ -1505,6 +1505,7 @@ module.exports = class Orders {
1505
1505
  console.error('%s %s query_order: %j', exchange, pair, res)
1506
1506
  }
1507
1507
  }
1508
+ const in_flight = new Set()
1508
1509
  let get_query_order_all = (Exchanges, exchange_pairs, interval_dict) => {
1509
1510
  let query_order = (exchange, pair) => {
1510
1511
  let order_info = _.get(this.get_order_info_by_order_type(types), [exchange, pair], {})
@@ -1514,27 +1515,38 @@ module.exports = class Orders {
1514
1515
  let order_number = _.keys(order_info['sell']).length + _.keys(order_info['buy']).length,
1515
1516
  count = 0,
1516
1517
  result = []
1518
+ const settle = () => {
1519
+ query_order_handler(exchange, pair, { success: true, body: result })
1520
+ clearTimeout(timeout)
1521
+ setTimeout(() => {
1522
+ query_order(exchange, pair)
1523
+ }, interval_dict[exchange].query_order)
1524
+ }
1525
+ if (order_number === 0) {
1526
+ return
1527
+ }
1517
1528
  for (let type in order_info) {
1518
1529
  for (let order_id in order_info[type]) {
1519
1530
  let { open_time } = order_info[type][order_id]
1520
- // console.log(order_id, open_time, open_time < new Date() - 30 * 60 * 1000)
1531
+ const key = `${exchange}:${pair}:${type}:${order_id}`
1532
+ if (in_flight.has(key)) {
1533
+ count++
1534
+ if (count === order_number) settle()
1535
+ continue
1536
+ }
1521
1537
  if (open_time < Date.now() - QUERY_ORDER_TIME_IN_MS) {
1522
- // console.log('query_order_maker_1: %s %s %s', exchange, pair, order_id)
1538
+ in_flight.add(key)
1523
1539
  Exchanges[exchange].query_order(pair, order_id, (res) => {
1540
+ in_flight.delete(key)
1524
1541
  count++
1525
1542
  if (res.success) {
1526
1543
  result.push(res.body)
1527
1544
  }
1528
- if (count === order_number) {
1529
- query_order_handler(exchange, pair, { success: true, body: result })
1530
- clearTimeout(timeout)
1531
- setTimeout(() => {
1532
- query_order(exchange, pair)
1533
- }, interval_dict[exchange].query_order)
1534
- }
1545
+ if (count === order_number) settle()
1535
1546
  })
1536
1547
  } else {
1537
1548
  count++
1549
+ if (count === order_number) settle()
1538
1550
  }
1539
1551
  }
1540
1552
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.21.23",
3
+ "version": "1.21.25",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {