@icgio/icg-exchanges-wrapper 1.17.24 → 1.17.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.
@@ -162,9 +162,6 @@ const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enab
162
162
  return
163
163
  }
164
164
 
165
- // Store promise before starting connection
166
- ws_connection_promises[ws_key] = ws_promise
167
-
168
165
  // Create WebSocket with ALL pairs collected in first pass
169
166
  // This ensures only ONE WebSocket per exchange, even with multiple clients/pairs
170
167
  Exchange.ws_market(all_pairs)
@@ -308,19 +305,12 @@ const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enab
308
305
 
309
306
  check_status()
310
307
  })
311
- // Clean up promise reference when done (but keep connection open for reuse)
312
- ws_promise.finally(() => {
313
- // Don't delete immediately - keep for a short time to allow reuse
314
- setTimeout(() => {
315
- if (ws_connection_promises[ws_key] === ws_promise) {
316
- delete ws_connection_promises[ws_key]
317
- // Also clean up wrapped promise if it exists
318
- if (ws_connection_promises_with_fallback[ws_key]) {
319
- delete ws_connection_promises_with_fallback[ws_key]
320
- }
321
- }
322
- }, 1000)
323
- })
308
+ // Store the cached promise AFTER `new Promise(...)` returns assigning inside
309
+ // the synchronous executor reads the outer binding while it's still undefined.
310
+ // Keep the entry alive while the socket is alive; the next tick's
311
+ // `is_opening_or_opened` check reads `Exchange.ws.market.status` and the
312
+ // else-branch above overwrites this slot when the socket is closed/stopped.
313
+ ws_connection_promises[ws_key] = ws_promise
324
314
  }
325
315
 
326
316
  // Wrap WebSocket promise to handle rejection and fall back to REST
@@ -445,9 +435,6 @@ const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, ti
445
435
  return
446
436
  }
447
437
 
448
- // Store promise before starting connection
449
- ws_market_history_promises[ws_key] = ws_promise
450
-
451
438
  // Only start if not already started (reuse connection from rates if available)
452
439
  // If starting new, use ALL pairs collected in first pass
453
440
  if (!first_time[Exchange_name]) {
@@ -589,18 +576,11 @@ const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, ti
589
576
  }
590
577
  check_status()
591
578
  })
592
- // Clean up promise reference when done (but keep connection open for reuse)
593
- ws_promise.finally(() => {
594
- setTimeout(() => {
595
- if (ws_market_history_promises[ws_key] === ws_promise) {
596
- delete ws_market_history_promises[ws_key]
597
- // Also clean up wrapped promise if it exists
598
- if (ws_market_history_promises_with_fallback[ws_key]) {
599
- delete ws_market_history_promises_with_fallback[ws_key]
600
- }
601
- }
602
- }, 1000)
603
- })
579
+ // Store the cached promise AFTER `new Promise(...)` returns assigning inside
580
+ // the synchronous executor reads the outer binding while it's still undefined.
581
+ // Keep the entry alive while the socket is alive; the else-branch above
582
+ // overwrites this slot when the socket is closed/stopped.
583
+ ws_market_history_promises[ws_key] = ws_promise
604
584
  }
605
585
 
606
586
  // If WebSocket promise rejects (timeout/error), fall back to REST for all pairs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.17.24",
3
+ "version": "1.17.26",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {