@icgio/icg-exchanges-wrapper 1.17.14 → 1.17.16

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.
@@ -374,26 +374,6 @@ const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enab
374
374
  })
375
375
 
376
376
  promises = promises.concat(rate_promises) // Add all rate promises
377
- } else if (Exchange.rate_with_routes) {
378
- let pairs_to_fetch = exchange_pair_dict[Exchange_name] || all_pairs
379
- let rate_with_routes_promises = pairs_to_fetch.map((pair) => {
380
- return new Promise((resolve, reject) => {
381
- Exchange.rate_with_routes(pair, function (res) {
382
- if (res.success) {
383
- let { asks, bids } = res.body
384
- asks = asks.map((ask) => ask.slice(0, 2))
385
- bids = bids.map((bid) => bid.slice(0, 2))
386
- set_pair_data(exchange_pair_rates, pair_exchange_rates, Exchange_name, pair, { asks, bids })
387
- } else {
388
- console.error(`getting rate with routes failed for ${Exchange_name} ${pair}:`, res)
389
- delete_pair_data(exchange_pair_rates, pair_exchange_rates, Exchange_name, pair)
390
- }
391
- resolve()
392
- })
393
- })
394
- })
395
-
396
- promises = promises.concat(rate_with_routes_promises) // Add all rate_with_routes promises
397
377
  }
398
378
  }
399
379
  }
@@ -200,7 +200,6 @@ module.exports = class Orders {
200
200
  this.trades = {}
201
201
  this.query_order = {}
202
202
  this.rates = {}
203
- this.rates_with_routes = {}
204
203
  this.rates_observable = new Observable()
205
204
  this.market_history = {}
206
205
  this.ohlcv = {}
@@ -209,7 +208,8 @@ module.exports = class Orders {
209
208
  this.buy_sell_limits_against_reserve_balance = {}
210
209
  this.order_info = {}
211
210
  this.fill_records = [] // { side, usdt_amount, timestamp, order_type }
212
- this.order_info_status = {}
211
+ this.order_status_index = {}
212
+ this.order_info_by_type = {}
213
213
  this.function_enabled = settings.function_enabled || {
214
214
  balances_check: true,
215
215
  positions_check: false,
@@ -319,39 +319,7 @@ module.exports = class Orders {
319
319
  }
320
320
  }, NO_CALLBACK_TIMEOUT_MS)
321
321
  let limit_trade = (cb) => {
322
- if (this.Exchanges[exchange].exchange_type === 'dex') {
323
- let rates_with_routes = this.rates_with_routes[exchange][pair]
324
- let routes
325
- if (method === 'buy') {
326
- let closest_level = _.minBy(rates_with_routes.asks, (ask) => {
327
- return Math.abs(ask[0] - price)
328
- })
329
- routes = [closest_level[2]]
330
- // for (let ask of rates_with_routes.asks) {
331
- // if (ask[0] === price) {
332
- // routes = [ask[2]]
333
- // }
334
- // }
335
- } else {
336
- let closest_level = _.minBy(rates_with_routes.bids, (bid) => {
337
- return Math.abs(bid[0] - price)
338
- })
339
- routes = [closest_level[2]]
340
- // for (let bid of rates_with_routes.bids) {
341
- // if (bid[0] === price) {
342
- // routes = [bid[2]]
343
- // }
344
- // }
345
- }
346
- if (routes) {
347
- if (this.Exchanges[exchange].private_limiter) {
348
- this.Exchanges[exchange].private_limiter.priority = getOrderPriority(order_type)
349
- }
350
- this.Exchanges[exchange].limit_trade_with_routes(pair, method, price, amount, routes, cb)
351
- } else {
352
- console.error('dex no routes:', rates_with_routes, price)
353
- }
354
- } else if (limiter_on) {
322
+ if (limiter_on) {
355
323
  if (this.Exchanges[exchange].private_limiter) {
356
324
  this.Exchanges[exchange].private_limiter.priority = getOrderPriority(order_type)
357
325
  }
@@ -493,34 +461,68 @@ module.exports = class Orders {
493
461
  }
494
462
  return stats
495
463
  }
464
+ has_orders_by_type(order_type, exchange, pair, side) {
465
+ const bucket = this.order_info_by_type[order_type]?.[exchange]?.[pair]?.[side]
466
+ if (!bucket) return false
467
+ for (const _ in bucket) return true
468
+ return false
469
+ }
496
470
  get_order_info_by_order_type(order_type) {
497
- let order_info_temp = {}
498
- for (let exchange in this.order_info) {
499
- for (let pair in this.order_info[exchange]) {
500
- for (let type in this.order_info[exchange][pair]) {
501
- for (let order_id in this.order_info[exchange][pair][type]) {
502
- const order_type_temp = _.get(this.order_info, [exchange, pair, type, order_id, 'order_type'])
503
- if ((Array.isArray(order_type) && order_type.includes(order_type_temp)) || order_type_temp === order_type) {
504
- _.setWith(order_info_temp, `${exchange}.${pair}.${type}.${order_id}`, _.get(this.order_info, `${exchange}.${pair}.${type}.${order_id}`), Object)
471
+ const types = Array.isArray(order_type) ? order_type : [order_type]
472
+ const result = {}
473
+ // Walk only the index sub-trees for the requested order_type(s). The
474
+ // returned dict is freshly built (preserving the original semantics that
475
+ // callers may add/remove top-level keys without affecting the canonical
476
+ // store) but the leaf order objects are still refs into this.order_info.
477
+ for (const t of types) {
478
+ const sub = this.order_info_by_type[t]
479
+ if (!sub) continue
480
+ for (const exchange in sub) {
481
+ const exch_sub = sub[exchange]
482
+ let result_exch = result[exchange]
483
+ if (!result_exch) {
484
+ result_exch = {}
485
+ result[exchange] = result_exch
486
+ }
487
+ for (const pair in exch_sub) {
488
+ const pair_sub = exch_sub[pair]
489
+ let result_pair = result_exch[pair]
490
+ if (!result_pair) {
491
+ result_pair = {}
492
+ result_exch[pair] = result_pair
493
+ }
494
+ for (const inner_type in pair_sub) {
495
+ const type_sub = pair_sub[inner_type]
496
+ let result_type = result_pair[inner_type]
497
+ if (!result_type) {
498
+ result_type = {}
499
+ result_pair[inner_type] = result_type
500
+ }
501
+ for (const order_id in type_sub) {
502
+ result_type[order_id] = type_sub[order_id]
505
503
  }
506
504
  }
507
505
  }
508
506
  }
509
507
  }
510
- return order_info_temp
508
+ return result
511
509
  }
512
510
  get_order_info_status_all(exchange, pair, type, status) {
513
511
  if (type === 'both') {
514
512
  return this.get_order_info_status_all(exchange, pair, 'sell', status).concat(this.get_order_info_status_all(exchange, pair, 'buy', status))
515
513
  }
516
- _.set(this.order_info_status, [exchange, pair, type, status], [])
517
- for (let order_id in _.get(this.order_info, [exchange, pair, type], {})) {
518
- let order_status = _.get(this.order_info, [exchange, pair, type, order_id, 'status'])
519
- if (order_status === status || _.includes(status, order_status)) {
520
- this.order_info_status[exchange][pair][type][status].push(this.order_info[exchange][pair][type][order_id])
514
+ const buckets_by_status = this.order_status_index[exchange]?.[pair]?.[type]
515
+ if (!buckets_by_status) return []
516
+ if (Array.isArray(status)) {
517
+ const result = []
518
+ for (const s of status) {
519
+ const bucket = buckets_by_status[s]
520
+ if (bucket) for (const order of bucket) result.push(order)
521
521
  }
522
+ return result
522
523
  }
523
- return this.order_info_status[exchange][pair][type][status]
524
+ const bucket = buckets_by_status[status]
525
+ return bucket ? Array.from(bucket) : []
524
526
  }
525
527
  get_order_info_status_by_order_type(exchange, pair, type, status, order_type) {
526
528
  return this.get_order_info_status_all(exchange, pair, type, status).filter((o) => o.order_type === order_type)
@@ -656,7 +658,7 @@ module.exports = class Orders {
656
658
  let order_info_order = this.order_info[exchange][pair][type][order_id]
657
659
  if (
658
660
  (order_info_order.status === 'N-FILLED' || order_info_order.status === 'P-FILLED') &&
659
- order_info_order.open_time < new Date().getTime() - this.no_trades_function_f_filled_timeout
661
+ order_info_order.open_time < Date.now() - this.no_trades_function_f_filled_timeout
660
662
  ) {
661
663
  let exist = false
662
664
  open_orders[exchange][pair].open_orders.map((o) => {
@@ -803,6 +805,11 @@ module.exports = class Orders {
803
805
  console.error('UPDATE %s: order_id invalid %s %s %s %s %j', note, exchange, pair, type, order_id, dict)
804
806
  return
805
807
  }
808
+
809
+ const existing = this.order_info[exchange]?.[pair]?.[type]?.[order_id]
810
+ const old_status = existing && existing.status
811
+ const old_order_type = existing && existing.order_type
812
+
806
813
  for (let key in dict) {
807
814
  if (key === 'f_percentage') {
808
815
  dict[key] = Math.round(dict[key] * 100) / 100
@@ -814,15 +821,37 @@ module.exports = class Orders {
814
821
  _.setWith(this.order_info, `${exchange}.${pair}.${type}.${order_id}.${key}`, dict[key], Object)
815
822
  }
816
823
 
817
- // Add trace entry for order history
818
- const trace_entry = {
819
- ts: Date.now(),
820
- status: dict.status || _.get(this.order_info, [exchange, pair, type, order_id, 'status']),
821
- note,
822
- f_amount: dict.f_amount,
824
+ const order = this.order_info[exchange][pair][type][order_id]
825
+ order.last_update_ts = Date.now()
826
+
827
+ const new_status = order.status
828
+ if (old_status !== new_status) {
829
+ if (old_status) {
830
+ const old_bucket = this.order_status_index[exchange]?.[pair]?.[type]?.[old_status]
831
+ if (old_bucket) old_bucket.delete(order)
832
+ }
833
+ if (new_status) {
834
+ const by_exch = this.order_status_index[exchange] || (this.order_status_index[exchange] = {})
835
+ const by_pair = by_exch[pair] || (by_exch[pair] = {})
836
+ const by_type = by_pair[type] || (by_pair[type] = {})
837
+ const bucket = by_type[new_status] || (by_type[new_status] = new Set())
838
+ bucket.add(order)
839
+ }
840
+ }
841
+ const new_order_type = order.order_type
842
+ if (old_order_type !== new_order_type) {
843
+ if (old_order_type) {
844
+ const at = this.order_info_by_type[old_order_type]?.[exchange]?.[pair]?.[type]
845
+ if (at) delete at[order_id]
846
+ }
847
+ if (new_order_type) {
848
+ const by_type = this.order_info_by_type[new_order_type] || (this.order_info_by_type[new_order_type] = {})
849
+ const by_exch = by_type[exchange] || (by_type[exchange] = {})
850
+ const by_pair = by_exch[pair] || (by_exch[pair] = {})
851
+ const by_inner_type = by_pair[type] || (by_pair[type] = {})
852
+ by_inner_type[order_id] = order
853
+ }
823
854
  }
824
- const existing_trace = _.get(this.order_info, [exchange, pair, type, order_id, 'trace'], [])
825
- _.setWith(this.order_info, `${exchange}.${pair}.${type}.${order_id}.trace`, [...existing_trace, trace_entry], Object)
826
855
 
827
856
  console.log('UPDATE %s: %s %s %s %s %j', note, exchange, pair, type, order_id, dict)
828
857
  // start: log every f-filled trade for future analysis
@@ -865,7 +894,19 @@ module.exports = class Orders {
865
894
  }
866
895
  delete_order_info(exchange, pair, type, order_id, note) {
867
896
  const order_data = _.get(this.order_info, [exchange, pair, type, order_id], {})
868
- this.order_info[exchange][pair][type] = _.omit(this.order_info[exchange][pair][type], [order_id])
897
+
898
+ if (order_data.status) {
899
+ const bucket = this.order_status_index[exchange]?.[pair]?.[type]?.[order_data.status]
900
+ if (bucket) bucket.delete(order_data)
901
+ }
902
+ if (order_data.order_type) {
903
+ const at = this.order_info_by_type[order_data.order_type]?.[exchange]?.[pair]?.[type]
904
+ if (at) delete at[order_id]
905
+ }
906
+
907
+ if (this.order_info[exchange]?.[pair]?.[type]) {
908
+ delete this.order_info[exchange][pair][type][order_id]
909
+ }
869
910
  console.log('DELETE %s: %s %s %s %s', note, exchange, pair, type, order_id)
870
911
 
871
912
  // Send delete event via WebSocket (only for non-INIT orders)
@@ -885,28 +926,17 @@ module.exports = class Orders {
885
926
  let balances_handler = (exchange, res) => {
886
927
  if (res.success) {
887
928
  _.set(this.balances, [exchange], Object.assign(res.body, { update_time: new Date() }))
888
- for (let exchange in this.exchange_cur_quote_cur) {
889
- for (let quote_cur in this.exchange_cur_quote_cur[exchange]) {
890
- this.exchange_cur_quote_cur[exchange][quote_cur].map((cur) => {
891
- let cur_balance = _.get(this.balances, [exchange, 'available', cur], 0)
892
- let quote_cur_balance = _.get(this.balances, [exchange, 'available', quote_cur], 0)
893
- let pair = cur + quote_cur
929
+ const cur_quote_cur = this.exchange_cur_quote_cur[exchange]
930
+ if (cur_quote_cur) {
931
+ for (let quote_cur in cur_quote_cur) {
932
+ cur_quote_cur[quote_cur].map((cur) => {
933
+ const cur_balance = _.get(this.balances, [exchange, 'available', cur], 0)
934
+ const quote_cur_balance = _.get(this.balances, [exchange, 'available', quote_cur], 0)
935
+ const pair = cur + quote_cur
894
936
  let max_cur_amount = cur_balance - _.get(this.min_reserve_balance, [exchange, cur], 0)
895
937
  let max_quote_cur_amount = quote_cur_balance - _.get(this.min_reserve_balance, [exchange, quote_cur], 0)
896
- if (max_cur_amount > 0) {
897
- } else {
898
- // if (cur_balance > 0) {
899
- // console.log('balance low', exchange, cur, cur_balance, this.min_reserve_balance[exchange][cur])
900
- // }
901
- max_cur_amount = 0
902
- }
903
- if (max_quote_cur_amount > 0) {
904
- } else {
905
- // if (quote_cur_balance > 0) {
906
- // console.log('balance low', exchange, quote_cur, quote_cur_balance, this.min_reserve_balance[exchange][quote_cur])
907
- // }
908
- max_quote_cur_amount = 0
909
- }
938
+ if (max_cur_amount < 0) max_cur_amount = 0
939
+ if (max_quote_cur_amount < 0) max_quote_cur_amount = 0
910
940
  _.set(this.buy_sell_limits_against_reserve_balance, [exchange, pair], {
911
941
  sell: max_cur_amount,
912
942
  buy: max_quote_cur_amount,
@@ -918,10 +948,10 @@ module.exports = class Orders {
918
948
  this.account_init = true
919
949
  this.init_account(this.balances, this.accounting_benchmark || this.balance_benchmark) // use accounting_benchmark if it exists
920
950
  }
921
- } else if (_.get(this.balances, [exchange, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].balances) {
951
+ } else if (_.get(this.balances, [exchange, 'update_time']) < Date.now() - this.interval_dict[exchange].balances) {
922
952
  console.log('%s balances expired: %j', exchange, res)
923
- this.balances = _.omit(this.balances, [exchange])
924
- this.buy_sell_limits_against_reserve_balance = _.omit(this.buy_sell_limits_against_reserve_balance, [exchange])
953
+ delete this.balances[exchange]
954
+ delete this.buy_sell_limits_against_reserve_balance[exchange]
925
955
  }
926
956
  }
927
957
  function get_balances(Exchanges, interval_dict) {
@@ -949,9 +979,9 @@ module.exports = class Orders {
949
979
  let position_all_handler = (exchange, res) => {
950
980
  if (res.success) {
951
981
  _.set(this.positions, [exchange], Object.assign(res.body, { update_time: new Date() }))
952
- } else if (_.get(this.positions, [exchange, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].positions) {
982
+ } else if (_.get(this.positions, [exchange, 'update_time']) < Date.now() - this.interval_dict[exchange].positions) {
953
983
  console.log('%s positions expired: %j', exchange, res)
954
- this.positions = _.omit(this.positions, [exchange])
984
+ delete this.positions[exchange]
955
985
  }
956
986
  }
957
987
  function get_positions(Exchanges, interval_dict) {
@@ -1018,18 +1048,21 @@ module.exports = class Orders {
1018
1048
  }
1019
1049
  }
1020
1050
  if (!this.previous_orders_canceled) {
1021
- let previous_orders_canceled = true
1022
- for (let exchange in this.exchange_pairs) {
1023
- this.exchange_pairs[exchange].map((pair) => {
1024
- if (!_.get(this.previous_orders_canceled_exchange_pair, [exchange, pair])) {
1025
- previous_orders_canceled = false
1051
+ let all_canceled = true
1052
+ outer: for (const exch of Object.keys(this.exchange_pairs)) {
1053
+ const pairs = this.exchange_pairs[exch]
1054
+ const exch_marks = this.previous_orders_canceled_exchange_pair[exch]
1055
+ for (let i = 0; i < pairs.length; i++) {
1056
+ if (!exch_marks || !exch_marks[pairs[i]]) {
1057
+ all_canceled = false
1058
+ break outer
1026
1059
  }
1027
- })
1060
+ }
1028
1061
  }
1029
- if (previous_orders_canceled) {
1062
+ if (all_canceled) {
1030
1063
  console.log('original order canceled')
1031
1064
  }
1032
- this.previous_orders_canceled = previous_orders_canceled
1065
+ this.previous_orders_canceled = all_canceled
1033
1066
  }
1034
1067
  }
1035
1068
  let rate_major = _.get(this.rates_combined_major, [pair])
@@ -1053,9 +1086,9 @@ module.exports = class Orders {
1053
1086
  if (res.success) {
1054
1087
  _.set(this.open_orders, [exchange, pair], { open_orders: res.body, update_time: new Date() })
1055
1088
  previous_orders_processer(exchange, pair, res.body)
1056
- } else if (_.get(this.open_orders, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].open_orders) {
1089
+ } else if (_.get(this.open_orders, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].open_orders) {
1057
1090
  console.log('%s %s open orders expired: %j', exchange, pair, res)
1058
- this.open_orders[exchange] = _.omit(this.open_orders[exchange], [pair])
1091
+ if (this.open_orders[exchange]) delete this.open_orders[exchange][pair]
1059
1092
  } else if (res.error !== 'opening') {
1060
1093
  console.error('%s %s open orders: %j', exchange, pair, res)
1061
1094
  }
@@ -1070,12 +1103,12 @@ module.exports = class Orders {
1070
1103
  } else {
1071
1104
  let error_logged = false
1072
1105
  for (let pair of this.exchange_pairs[exchange]) {
1073
- if (_.get(this.open_orders, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].open_orders) {
1106
+ if (_.get(this.open_orders, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].open_orders) {
1074
1107
  if (!error_logged) {
1075
1108
  console.log('%s all open orders expired: %j', exchange, res)
1076
1109
  error_logged = true
1077
1110
  }
1078
- this.open_orders[exchange] = _.omit(this.open_orders[exchange], [pair])
1111
+ if (this.open_orders[exchange]) delete this.open_orders[exchange][pair]
1079
1112
  } else if (res.error !== 'opening' && !error_logged) {
1080
1113
  console.error('%s all open orders: %j', exchange, res)
1081
1114
  error_logged = true
@@ -1118,11 +1151,6 @@ module.exports = class Orders {
1118
1151
  })
1119
1152
  }
1120
1153
  for (let exchange in Exchanges) {
1121
- if (Exchanges[exchange].exchange_type === 'dex') {
1122
- for (let pair of exchange_pairs[exchange]) {
1123
- _.set(this.previous_orders_canceled_exchange_pair, [exchange, pair], true)
1124
- }
1125
- }
1126
1154
  if (Exchanges[exchange].get_all_open_orders_ws) {
1127
1155
  if (Exchanges[exchange].ws_status().trading === 'n-opened') Exchanges[exchange].ws_account()
1128
1156
  get_all_open_orders_ws(exchange)
@@ -1151,13 +1179,13 @@ module.exports = class Orders {
1151
1179
  this.trades_amount_past_hour,
1152
1180
  [exchange, pair],
1153
1181
  _.sumBy(
1154
- res.body.filter((t) => t.close_time > new Date().getTime() - ONE_HOUR_IN_MS || t.open_time > new Date().getTime() - ONE_HOUR_IN_MS),
1182
+ res.body.filter((t) => t.close_time > Date.now() - ONE_HOUR_IN_MS || t.open_time > Date.now() - ONE_HOUR_IN_MS),
1155
1183
  (t) => t.amount,
1156
1184
  ) || 0,
1157
1185
  )
1158
- } else if (_.get(this.trades, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].trades) {
1186
+ } else if (_.get(this.trades, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].trades) {
1159
1187
  console.log('%s %s trades expired: %j', exchange, pair, res)
1160
- this.trades[exchange] = _.omit(this.trades[exchange], [pair])
1188
+ if (this.trades[exchange]) delete this.trades[exchange][pair]
1161
1189
  } else if (res.error !== 'opening') {
1162
1190
  console.error('%s %s trades: %j', exchange, pair, res)
1163
1191
  }
@@ -1171,7 +1199,7 @@ module.exports = class Orders {
1171
1199
  this.trades_amount_past_hour,
1172
1200
  [exchange, pair],
1173
1201
  _.sumBy(
1174
- trades.filter((t) => t.close_time > new Date().getTime() - ONE_HOUR_IN_MS || t.open_time > new Date().getTime() - ONE_HOUR_IN_MS),
1202
+ trades.filter((t) => t.close_time > Date.now() - ONE_HOUR_IN_MS || t.open_time > Date.now() - ONE_HOUR_IN_MS),
1175
1203
  (t) => t.amount,
1176
1204
  ) || 0,
1177
1205
  )
@@ -1179,12 +1207,12 @@ module.exports = class Orders {
1179
1207
  } else if (res.error !== 'opening') {
1180
1208
  let error_logged = false
1181
1209
  for (let pair of this.exchange_pairs[exchange]) {
1182
- if (_.get(this.trades, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].trades) {
1210
+ if (_.get(this.trades, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].trades) {
1183
1211
  if (!error_logged) {
1184
1212
  console.log('%s all trades expired: %j', exchange, res)
1185
1213
  error_logged = true
1186
1214
  }
1187
- this.trades[exchange] = _.omit(this.trades[exchange], [pair])
1215
+ if (this.trades[exchange]) delete this.trades[exchange][pair]
1188
1216
  } else if (res.error !== 'opening' && !error_logged) {
1189
1217
  console.error('%s all trades: %j', exchange, res)
1190
1218
  error_logged = true
@@ -1283,9 +1311,9 @@ module.exports = class Orders {
1283
1311
  let query_order_handler = (exchange, pair, res) => {
1284
1312
  if (res.success) {
1285
1313
  _.set(this.query_order, [exchange, pair], { query_order: res.body, update_time: new Date() })
1286
- } else if (_.get(this.query_order, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].query_order) {
1314
+ } else if (_.get(this.query_order, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].query_order) {
1287
1315
  console.log('%s %s query_order expired: %j', exchange, pair, res)
1288
- this.query_order[exchange] = _.omit(this.query_order[exchange], [pair])
1316
+ if (this.query_order[exchange]) delete this.query_order[exchange][pair]
1289
1317
  } else if (res.error !== 'opening') {
1290
1318
  console.error('%s %s query_order: %j', exchange, pair, res)
1291
1319
  }
@@ -1341,7 +1369,7 @@ module.exports = class Orders {
1341
1369
  let exchanges_list = _.concat(this.pair_exchanges[pair] || [], this.pair_exchanges_rates_only[pair] || [])
1342
1370
  for (let exchange of exchanges_list) {
1343
1371
  if (_.get(this.rates, [exchange, pair, 'asks'], []).length > 0 && _.get(this.rates, [exchange, pair, 'bids'], []).length > 0) {
1344
- const rates = _.cloneDeep(this.rates[exchange][pair])
1372
+ const rates = this.rates[exchange][pair]
1345
1373
 
1346
1374
  let major_rates_only_exchanges_length = _.get(this.major_exchanges, [pair], []).length + _.get(this.rates_only_exchanges, [pair], []).length
1347
1375
  if (this.major_exchanges[pair] && _.includes(this.major_exchanges[pair], exchange)) {
@@ -1356,8 +1384,8 @@ module.exports = class Orders {
1356
1384
  }
1357
1385
  }
1358
1386
  } else {
1359
- orderbook_major = _.omit(orderbook_major, [exchange])
1360
- orderbook_major_temp = _.omit(orderbook_major_temp, [exchange])
1387
+ delete orderbook_major[exchange]
1388
+ delete orderbook_major_temp[exchange]
1361
1389
  }
1362
1390
  }
1363
1391
 
@@ -1365,7 +1393,7 @@ module.exports = class Orders {
1365
1393
  if (o_3.asks.length > 0 && o_3.bids.length > 0) {
1366
1394
  _.set(this.rates_combined_major, [pair], o_3)
1367
1395
  } else {
1368
- this.rates_combined_major = _.omit(this.rates_combined_major, [pair])
1396
+ delete this.rates_combined_major[pair]
1369
1397
  }
1370
1398
 
1371
1399
  const reference_pair = this.pair_map_rates_only[pair]
@@ -1376,14 +1404,9 @@ module.exports = class Orders {
1376
1404
  this.rates_observable.notify()
1377
1405
  }
1378
1406
  const throttled_process_rates = _.throttle(process_rates, PROCESS_RATES_THROTTLE_MS, { leading: true, trailing: true })
1379
- let rates_handler = (exchange, pair, res, rates_with_routes = false) => {
1407
+ let rates_handler = (exchange, pair, res) => {
1380
1408
  if (res.success) {
1381
1409
  let { asks, bids } = res.body
1382
- if (rates_with_routes) {
1383
- _.set(this.rates_with_routes, [exchange, pair], { asks, bids, update_time: new Date() })
1384
- asks = asks.map((ask) => ask.slice(0, 2))
1385
- bids = bids.map((bid) => bid.slice(0, 2))
1386
- }
1387
1410
  asks = asks.slice(0, RATES_LENGTH_MAX)
1388
1411
  bids = bids.slice(0, RATES_LENGTH_MAX)
1389
1412
  _.set(this.rates, [exchange, pair], { asks, bids, update_time: new Date() })
@@ -1391,9 +1414,9 @@ module.exports = class Orders {
1391
1414
  * throttle to 20ms
1392
1415
  */
1393
1416
  throttled_process_rates()
1394
- } else if (_.get(this.rates, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].rates) {
1417
+ } else if (_.get(this.rates, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].rates) {
1395
1418
  console.log('%s %s rates expired: %j', exchange, pair, res)
1396
- this.rates[exchange] = _.omit(this.rates[exchange], [pair])
1419
+ if (this.rates[exchange]) delete this.rates[exchange][pair]
1397
1420
  this.rates_observable.notify()
1398
1421
  }
1399
1422
  }
@@ -1412,19 +1435,6 @@ module.exports = class Orders {
1412
1435
  rates_handler(exchange, pair, res)
1413
1436
  })
1414
1437
  }
1415
- } else if (Exchanges[exchange].ws_market && Exchanges[exchange].exchange_type === 'dex') {
1416
- setInterval(() => {
1417
- if (!this.ws_market_first_time[exchange]) {
1418
- Exchanges[exchange].ws_market(exchange_pairs[exchange], this.ws_market_options)
1419
- this.ws_market_first_time[exchange] = true
1420
- } else {
1421
- for (let pair of exchange_pairs[exchange]) {
1422
- Exchanges[exchange].rate_with_routes_ws(pair, (res) => {
1423
- rates_handler(exchange, pair, res, true)
1424
- })
1425
- }
1426
- }
1427
- }, interval_dict[exchange].rates)
1428
1438
  } else if (Exchanges[exchange].exchange_type === 'spot') {
1429
1439
  for (let pair of exchange_pairs[exchange]) {
1430
1440
  setInterval(() => {
@@ -1433,14 +1443,6 @@ module.exports = class Orders {
1433
1443
  })
1434
1444
  }, interval_dict[exchange].rates)
1435
1445
  }
1436
- } else if (Exchanges[exchange].exchange_type === 'dex') {
1437
- for (let pair of exchange_pairs[exchange]) {
1438
- setInterval(() => {
1439
- Exchanges[exchange].rate_with_routes(pair, (res) => {
1440
- rates_handler(exchange, pair, res, true)
1441
- })
1442
- }, interval_dict[exchange].rates)
1443
- }
1444
1446
  }
1445
1447
  }
1446
1448
  for (let exchange in exchange_pairs_rates_only) {
@@ -1471,9 +1473,9 @@ module.exports = class Orders {
1471
1473
  let market_history_handler = (exchange, pair, res) => {
1472
1474
  if (res.success) {
1473
1475
  _.set(this.market_history, [exchange, pair], { data: res.body, update_time: new Date() })
1474
- } else if (_.get(this.market_history, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].market_history) {
1476
+ } else if (_.get(this.market_history, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].market_history) {
1475
1477
  console.log('%s %s market_history expired: %j', exchange, pair, res)
1476
- this.market_history[exchange] = _.omit(this.market_history[exchange], [pair])
1478
+ if (this.market_history[exchange]) delete this.market_history[exchange][pair]
1477
1479
  }
1478
1480
  }
1479
1481
  let get_market_history = (Exchanges, exchange_pairs, interval_dict) => {
@@ -1508,13 +1510,13 @@ module.exports = class Orders {
1508
1510
  if (res.success) {
1509
1511
  if (res.body.length < OHLCV_DEFAULT_PAST_HOURS) {
1510
1512
  console.error('ohlcv length should be:', OHLCV_DEFAULT_PAST_HOURS, exchange, pair, res.body.length, _.first(res.body), _.last(res.body))
1511
- this.ohlcv[exchange] = _.omit(this.ohlcv[exchange], [pair])
1513
+ if (this.ohlcv[exchange]) delete this.ohlcv[exchange][pair]
1512
1514
  } else {
1513
1515
  _.set(this.ohlcv, [exchange, pair], { data: res.body, update_time: new Date() })
1514
1516
  }
1515
- } else if (_.get(this.ohlcv, [exchange, pair, 'update_time']) < new Date().getTime() - this.interval_dict[exchange].ohlcv) {
1517
+ } else if (_.get(this.ohlcv, [exchange, pair, 'update_time']) < Date.now() - this.interval_dict[exchange].ohlcv) {
1516
1518
  console.log('%s %s ohlcv expired: %j', exchange, pair, res)
1517
- this.ohlcv[exchange] = _.omit(this.ohlcv[exchange], [pair])
1519
+ if (this.ohlcv[exchange]) delete this.ohlcv[exchange][pair]
1518
1520
  }
1519
1521
  }
1520
1522
  let get_ohlcv = (Exchanges, exchange_pairs, interval_dict) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.17.14",
3
+ "version": "1.17.16",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,7 +18,7 @@
18
18
  "homepage": "https://github.com/icgio/icg-exchanges-wrapper#readme",
19
19
  "dependencies": {
20
20
  "@icgio/icg-exchanges": "^1.40.29",
21
- "@icgio/icg-utils": "^1.9.53",
21
+ "@icgio/icg-utils": "^1.9.55",
22
22
  "lodash": "^4.17.23",
23
23
  "pg": "^8.17.2"
24
24
  }