@icgio/icg-exchanges-wrapper 1.21.24 → 1.21.26

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.
@@ -1493,8 +1493,7 @@ module.exports = class Orders {
1493
1493
  get_trades_all(this.Exchanges, this.exchange_pairs, this.interval_dict)
1494
1494
  }
1495
1495
  check_query_order(exchange, order_types) {
1496
- // const QUERY_ORDER_TIME_IN_MS = 30 * 60 * 1000
1497
- const QUERY_ORDER_TIME_IN_MS = 0
1496
+ const QUERY_ORDER_TIME_IN_MS = 5 * 1000
1498
1497
  const types = order_types && order_types.length > 0 ? order_types : ['maker_1']
1499
1498
  let query_order_handler = (exchange, pair, res) => {
1500
1499
  if (res.success) {
@@ -1506,6 +1505,7 @@ module.exports = class Orders {
1506
1505
  console.error('%s %s query_order: %j', exchange, pair, res)
1507
1506
  }
1508
1507
  }
1508
+ const in_flight = new Set()
1509
1509
  let get_query_order_all = (Exchanges, exchange_pairs, interval_dict) => {
1510
1510
  let query_order = (exchange, pair) => {
1511
1511
  let order_info = _.get(this.get_order_info_by_order_type(types), [exchange, pair], {})
@@ -1515,27 +1515,38 @@ module.exports = class Orders {
1515
1515
  let order_number = _.keys(order_info['sell']).length + _.keys(order_info['buy']).length,
1516
1516
  count = 0,
1517
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
+ }
1518
1528
  for (let type in order_info) {
1519
1529
  for (let order_id in order_info[type]) {
1520
1530
  let { open_time } = order_info[type][order_id]
1521
- // 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
+ }
1522
1537
  if (open_time < Date.now() - QUERY_ORDER_TIME_IN_MS) {
1523
- // console.log('query_order_maker_1: %s %s %s', exchange, pair, order_id)
1538
+ in_flight.add(key)
1524
1539
  Exchanges[exchange].query_order(pair, order_id, (res) => {
1540
+ in_flight.delete(key)
1525
1541
  count++
1526
1542
  if (res.success) {
1527
1543
  result.push(res.body)
1528
1544
  }
1529
- if (count === order_number) {
1530
- query_order_handler(exchange, pair, { success: true, body: result })
1531
- clearTimeout(timeout)
1532
- setTimeout(() => {
1533
- query_order(exchange, pair)
1534
- }, interval_dict[exchange].query_order)
1535
- }
1545
+ if (count === order_number) settle()
1536
1546
  })
1537
1547
  } else {
1538
1548
  count++
1549
+ if (count === order_number) settle()
1539
1550
  }
1540
1551
  }
1541
1552
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.21.24",
3
+ "version": "1.21.26",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
19
19
  "dependencies": {
20
- "@icgio/icg-exchanges": "^1.45.12",
20
+ "@icgio/icg-exchanges": "^1.45.13",
21
21
  "@icgio/icg-utils": "^1.9.62",
22
22
  "lodash": "^4.17.23",
23
23
  "pg": "^8.17.2"