@icgio/icg-exchanges-wrapper 1.17.25 → 1.17.27

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,9 +305,12 @@ const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enab
308
305
 
309
306
  check_status()
310
307
  })
311
- // Keep the cached promise as long as the underlying socket is alive.
312
- // The next tick's `is_opening_or_opened` check reads `Exchange.ws.market.status`;
313
- // when that flips to 'closed'/'stopped' the else-branch below overwrites this slot.
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
314
314
  }
315
315
 
316
316
  // Wrap WebSocket promise to handle rejection and fall back to REST
@@ -435,9 +435,6 @@ const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, ti
435
435
  return
436
436
  }
437
437
 
438
- // Store promise before starting connection
439
- ws_market_history_promises[ws_key] = ws_promise
440
-
441
438
  // Only start if not already started (reuse connection from rates if available)
442
439
  // If starting new, use ALL pairs collected in first pass
443
440
  if (!first_time[Exchange_name]) {
@@ -579,9 +576,12 @@ const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, ti
579
576
  }
580
577
  check_status()
581
578
  })
582
- // Keep the cached promise as long as the underlying socket is alive.
583
- // The next tick's `is_opening_or_opened` check reads `Exchange.ws.market.status`;
584
- // when that flips to 'closed'/'stopped' the else-branch below overwrites this slot.
579
+ // Do NOT cache this promise. `Exchange.market_history_ws(pair, tf, cb)` returns a
580
+ // filtered/sorted SNAPSHOT of `market_history_dict[pair]` at call time (see icg-exchanges
581
+ // mexc.js:214), so the result is frozen once the promise resolves. Rerunning the else
582
+ // branch each poll lets a new `market_history_ws` call pick up trades the WebSocket has
583
+ // appended since last tick; `first_time[Exchange_name]` still prevents the underlying
584
+ // WS from being reopened, so there's no reconnect cost.
585
585
  }
586
586
 
587
587
  // 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.25",
3
+ "version": "1.17.27",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {