@icgio/icg-exchanges-wrapper 1.17.22 → 1.17.24

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.
@@ -97,6 +97,29 @@ const hrtime_diff = (start, end) => {
97
97
  return (end[0] - start[0]) * 1e9 + (end[1] - start[1])
98
98
  }
99
99
 
100
+ const is_finite_number = (value) => value != null && Number.isFinite(Number(value))
101
+
102
+ const normalize_market_ts = (raw_market_ts) => {
103
+ if (!raw_market_ts || typeof raw_market_ts !== 'object') {
104
+ return {}
105
+ }
106
+ return {
107
+ ts_ms_venue_event: is_finite_number(raw_market_ts.ts_ms_venue_event) ? Number(raw_market_ts.ts_ms_venue_event) : null,
108
+ ts_ms_venue_send: is_finite_number(raw_market_ts.ts_ms_venue_send) ? Number(raw_market_ts.ts_ms_venue_send) : null,
109
+ ts_ms_local_received: is_finite_number(raw_market_ts.ts_ms_local_received) ? Number(raw_market_ts.ts_ms_local_received) : null,
110
+ }
111
+ }
112
+
113
+ const public_decision_context = (decision_context) => {
114
+ if (!decision_context || typeof decision_context !== 'object') {
115
+ return null
116
+ }
117
+ const public_context = _.cloneDeep(decision_context)
118
+ delete public_context.hr_rate_root
119
+ delete public_context.hr_decision
120
+ return public_context
121
+ }
122
+
100
123
  module.exports = class Orders {
101
124
  constructor(exchange_cur_quote_cur_dict, cd, settings) {
102
125
  let { exchange_cur_quote_cur, exchange_cur_quote_cur_rates_only, pair_map_rates_only } = exchange_cur_quote_cur_dict
@@ -354,11 +377,9 @@ module.exports = class Orders {
354
377
  return
355
378
  }
356
379
  init_emitted = true
357
- const init_decision_context = decision_context ? { ...decision_context } : null
358
- const t2t_ns = hrtime_diff(init_decision_context?.t_decision_hr, t_order_sent)
359
- if (init_decision_context) {
360
- delete init_decision_context.t_decision_hr
361
- }
380
+ const init_decision_context = public_decision_context(decision_context)
381
+ const du_ns_decision_to_send = hrtime_diff(decision_context?.hr_decision, t_order_sent)
382
+ const du_ns_rate_to_send = hrtime_diff(decision_context?.hr_rate_root, t_order_sent)
362
383
  this.update_order_info(
363
384
  exchange,
364
385
  pair,
@@ -379,7 +400,8 @@ module.exports = class Orders {
379
400
  open_time: Date.now(),
380
401
  close_time: null,
381
402
  decision_context: init_decision_context,
382
- t2t_ns,
403
+ du_ns_decision_to_send,
404
+ du_ns_rate_to_send,
383
405
  event_hrtime: t_order_sent,
384
406
  },
385
407
  order_type + ' init',
@@ -427,7 +449,8 @@ module.exports = class Orders {
427
449
  f_percentage: 0,
428
450
  t_amount: amount,
429
451
  close_time: null,
430
- order_rtt_ns: hrtime_diff(_.get(res, ['meta', 't_order_sent']), _.get(res, ['meta', 't_ack_recv'])),
452
+ du_ns_rate_to_ack: hrtime_diff(decision_context?.hr_rate_root, _.get(res, ['meta', 't_ack_recv'])),
453
+ du_ns_order_rtt: hrtime_diff(_.get(res, ['meta', 't_order_sent']), _.get(res, ['meta', 't_ack_recv'])),
431
454
  event_hrtime: _.get(res, ['meta', 't_ack_recv']),
432
455
  },
433
456
  order_type + ' n-filled',
@@ -454,8 +477,9 @@ module.exports = class Orders {
454
477
  }
455
478
  })
456
479
  }
457
- cancel_order(exchange, pair, order) {
480
+ cancel_order(exchange, pair, order, decision_context = null) {
458
481
  let original_status = order.status
482
+ const cancel_decision_context = public_decision_context(decision_context) || _.cloneDeep(order.decision_context) || null
459
483
  this.update_order_info(
460
484
  exchange,
461
485
  pair,
@@ -463,6 +487,7 @@ module.exports = class Orders {
463
487
  order.order_id,
464
488
  {
465
489
  status: 'CANCELING',
490
+ decision_context: cancel_decision_context,
466
491
  },
467
492
  order.order_type + ' canceling',
468
493
  )
@@ -480,7 +505,9 @@ module.exports = class Orders {
480
505
  {
481
506
  status: 'CANCELED',
482
507
  close_time: Date.now(),
483
- cancel_latency_ns: hrtime_diff(_.get(res, ['meta', 't_cancel_sent']), _.get(res, ['meta', 't_cancel_ack'])),
508
+ decision_context: cancel_decision_context,
509
+ du_ns_cancel_latency: hrtime_diff(_.get(res, ['meta', 't_cancel_sent']), _.get(res, ['meta', 't_cancel_ack'])),
510
+ du_ns_rate_to_cancel_ack: hrtime_diff(decision_context?.hr_rate_root, _.get(res, ['meta', 't_cancel_ack'])),
484
511
  event_hrtime: _.get(res, ['meta', 't_cancel_ack']),
485
512
  },
486
513
  order.order_type + ' canceled',
@@ -1506,10 +1533,29 @@ module.exports = class Orders {
1506
1533
  const throttled_process_rates = _.throttle(process_rates, PROCESS_RATES_THROTTLE_MS, { leading: true, trailing: true })
1507
1534
  let rates_handler = (exchange, pair, res) => {
1508
1535
  if (res.success) {
1509
- let { asks, bids, _ts } = res.body
1536
+ const hr_rate_root = process.hrtime()
1537
+ const ts_ms_local_rate_root = Date.now()
1538
+ let { asks, bids, market_ts } = res.body
1539
+ const raw_market_ts = market_ts && typeof market_ts === 'object' ? market_ts : null
1540
+ const normalized_market_ts = normalize_market_ts(raw_market_ts)
1541
+ const prev_local_received = _.get(this.rates, [exchange, pair, 'market_ts', 'ts_ms_local_received'])
1542
+ const du_ms_interarrival_local_received =
1543
+ is_finite_number(prev_local_received) && is_finite_number(normalized_market_ts.ts_ms_local_received)
1544
+ ? Number(normalized_market_ts.ts_ms_local_received) - Number(prev_local_received)
1545
+ : null
1510
1546
  asks = asks.slice(0, RATES_LENGTH_MAX)
1511
1547
  bids = bids.slice(0, RATES_LENGTH_MAX)
1512
- _.set(this.rates, [exchange, pair], { asks, bids, _ts, update_time: new Date() })
1548
+ _.set(this.rates, [exchange, pair], {
1549
+ asks,
1550
+ bids,
1551
+ market_ts: normalized_market_ts,
1552
+ hr_rate_root,
1553
+ hr_recv: Array.isArray(raw_market_ts?.hr_recv) ? raw_market_ts.hr_recv : null,
1554
+ hr_parsed: Array.isArray(raw_market_ts?.hr_parsed) ? raw_market_ts.hr_parsed : null,
1555
+ ts_ms_local_rate_root,
1556
+ du_ms_interarrival_local_received,
1557
+ update_time: new Date(),
1558
+ })
1513
1559
  /*
1514
1560
  * throttle to 20ms
1515
1561
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.17.22",
3
+ "version": "1.17.24",
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.40.45",
20
+ "@icgio/icg-exchanges": "^1.41.0",
21
21
  "@icgio/icg-utils": "^1.9.61",
22
22
  "lodash": "^4.17.23",
23
23
  "pg": "^8.17.2"