@icgio/icg-exchanges-wrapper 1.14.257 → 1.14.259

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.
@@ -205,8 +205,11 @@ const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enab
205
205
  const ws_connection_ready = Exchange.ws.market.status === 'opening' || Exchange.ws.market.status === 'opened'
206
206
 
207
207
  if (ws_connection_ready) {
208
- // Try each pair individually - don't wait for all pairs to be ready
209
- // This allows us to detect individual pair failures
208
+ // Try each pair individually - wait a bit for pairs to become ready
209
+ // This allows us to detect individual pair failures while giving time for subscription
210
+ const PAIR_READY_TIMEOUT_MS = 10000 // Wait up to 10 seconds for pair to become ready
211
+ const PAIR_CHECK_INTERVAL_MS = 100 // Check every 100ms
212
+
210
213
  let rate_promises = pairs_to_check.map((pair) => {
211
214
  return new Promise((rate_resolve) => {
212
215
  // Check if this pair should skip WebSocket due to persistent failures
@@ -217,38 +220,52 @@ const get_exchanges_rates = function (Exchanges, exchange_pair_dict, cb, ws_enab
217
220
  return
218
221
  }
219
222
 
220
- // Check if this specific pair is ready before calling rate_ws
221
- const pair_ready = (
222
- Exchange.ws.market.pair_status &&
223
- Exchange.ws.market.pair_status[pair] === 'opened' &&
224
- Exchange.ws.market.asks_dict &&
225
- Exchange.ws.market.asks_dict[pair] &&
226
- Exchange.ws.market.asks_dict[pair].length > 0 &&
227
- Exchange.ws.market.bids_dict &&
228
- Exchange.ws.market.bids_dict[pair] &&
229
- Exchange.ws.market.bids_dict[pair].length > 0
230
- )
231
-
232
- if (!pair_ready) {
233
- // Pair not ready yet - mark as failed, will retry later or fall back to REST
234
- console.log(`[WebSocket] ${Exchange_name} ${pair}: Not ready yet (status: ${Exchange.ws.market.pair_status?.[pair] || 'unknown'})`)
235
- rate_resolve({ pair, failed: true })
236
- return
237
- }
238
-
239
- Exchange.rate_ws(pair, function (res) {
240
- if (res.success) {
241
- // Success - reset failure count
242
- reset_ws_failure(ws_failed_pairs, Exchange_name, pair)
243
- set_pair_data(exchange_pair_rates, pair_exchange_rates, Exchange_name, pair, res.body)
244
- rate_resolve({ pair, failed: false })
223
+ // Wait for pair to become ready with retry logic
224
+ const pair_start_time = Date.now()
225
+ const check_pair_ready = () => {
226
+ // Check if this specific pair is ready before calling rate_ws
227
+ const pair_ready = (
228
+ Exchange.ws.market.pair_status &&
229
+ Exchange.ws.market.pair_status[pair] === 'opened' &&
230
+ Exchange.ws.market.asks_dict &&
231
+ Exchange.ws.market.asks_dict[pair] &&
232
+ Exchange.ws.market.asks_dict[pair].length > 0 &&
233
+ Exchange.ws.market.bids_dict &&
234
+ Exchange.ws.market.bids_dict[pair] &&
235
+ Exchange.ws.market.bids_dict[pair].length > 0
236
+ )
237
+
238
+ if (pair_ready) {
239
+ // Pair is ready, try to get rate
240
+ Exchange.rate_ws(pair, function (res) {
241
+ if (res.success) {
242
+ // Success - reset failure count
243
+ reset_ws_failure(ws_failed_pairs, Exchange_name, pair)
244
+ set_pair_data(exchange_pair_rates, pair_exchange_rates, Exchange_name, pair, res.body)
245
+ rate_resolve({ pair, failed: false })
246
+ } else {
247
+ console.error(`getting rate ws failed for ${Exchange_name} ${pair}:`, res)
248
+ delete_pair_data(exchange_pair_rates, pair_exchange_rates, Exchange_name, pair)
249
+ track_ws_failure(ws_failed_pairs, Exchange_name, pair)
250
+ rate_resolve({ pair, failed: true })
251
+ }
252
+ })
245
253
  } else {
246
- console.error(`getting rate ws failed for ${Exchange_name} ${pair}:`, res)
247
- delete_pair_data(exchange_pair_rates, pair_exchange_rates, Exchange_name, pair)
248
- track_ws_failure(ws_failed_pairs, Exchange_name, pair)
249
- rate_resolve({ pair, failed: true })
254
+ // Pair not ready yet - check if we've exceeded timeout
255
+ const elapsed = Date.now() - pair_start_time
256
+ if (elapsed >= PAIR_READY_TIMEOUT_MS) {
257
+ // Timeout reached - mark as failed, will fall back to REST
258
+ console.log(`[WebSocket] ${Exchange_name} ${pair}: Not ready after ${elapsed}ms (status: ${Exchange.ws.market.pair_status?.[pair] || 'unknown'})`)
259
+ rate_resolve({ pair, failed: true })
260
+ } else {
261
+ // Retry after a short delay
262
+ setTimeout(check_pair_ready, PAIR_CHECK_INTERVAL_MS)
263
+ }
250
264
  }
251
- })
265
+ }
266
+
267
+ // Start checking
268
+ check_pair_ready()
252
269
  })
253
270
  })
254
271
  Promise.all(rate_promises)
@@ -500,8 +517,11 @@ const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, ti
500
517
  const ws_connection_ready = Exchange.ws.market.status === 'opening' || Exchange.ws.market.status === 'opened'
501
518
 
502
519
  if (ws_connection_ready) {
503
- // Try each pair individually - don't wait for all pairs to be ready
504
- // This allows us to detect individual pair failures
520
+ // Try each pair individually - wait a bit for pairs to become ready
521
+ // This allows us to detect individual pair failures while giving time for subscription
522
+ const PAIR_READY_TIMEOUT_MS = 10000 // Wait up to 10 seconds for pair to become ready
523
+ const PAIR_CHECK_INTERVAL_MS = 100 // Check every 100ms
524
+
505
525
  let market_history_promises = pairs_to_check.map((pair) => {
506
526
  return new Promise((rate_resolve) => {
507
527
  // Check if this pair should skip WebSocket due to persistent failures
@@ -512,35 +532,49 @@ const get_exchanges_market_history = function (Exchanges, exchange_pair_dict, ti
512
532
  return
513
533
  }
514
534
 
515
- // Check if this specific pair is ready before calling market_history_ws
516
- const pair_ready = (
517
- Exchange.ws.market.pair_status &&
518
- Exchange.ws.market.pair_status[pair] === 'opened' &&
519
- Exchange.ws.market.market_history_dict &&
520
- Exchange.ws.market.market_history_dict[pair] &&
521
- Exchange.ws.market.market_history_dict[pair].length >= 0
522
- )
523
-
524
- if (!pair_ready) {
525
- // Pair not ready yet - mark as failed, will retry later or fall back to REST
526
- console.log(`[WebSocket Market History] ${Exchange_name} ${pair}: Not ready yet (status: ${Exchange.ws.market.pair_status?.[pair] || 'unknown'})`)
527
- rate_resolve({ pair, failed: true })
528
- return
529
- }
530
-
531
- Exchange.market_history_ws(pair, timeframe_in_ms, function (res) {
532
- if (res.success) {
533
- // Success - reset failure count
534
- reset_ws_failure(ws_market_history_failed_pairs, Exchange_name, pair)
535
- set_pair_data(exchange_pair_market_history, pair_exchange_market_history, Exchange_name, pair, res.body)
536
- rate_resolve({ pair, failed: false })
535
+ // Wait for pair to become ready with retry logic
536
+ const pair_start_time = Date.now()
537
+ const check_pair_ready = () => {
538
+ // Check if this specific pair is ready before calling market_history_ws
539
+ const pair_ready = (
540
+ Exchange.ws.market.pair_status &&
541
+ Exchange.ws.market.pair_status[pair] === 'opened' &&
542
+ Exchange.ws.market.market_history_dict &&
543
+ Exchange.ws.market.market_history_dict[pair] &&
544
+ Exchange.ws.market.market_history_dict[pair].length >= 0
545
+ )
546
+
547
+ if (pair_ready) {
548
+ // Pair is ready, try to get market history
549
+ Exchange.market_history_ws(pair, timeframe_in_ms, function (res) {
550
+ if (res.success) {
551
+ // Success - reset failure count
552
+ reset_ws_failure(ws_market_history_failed_pairs, Exchange_name, pair)
553
+ set_pair_data(exchange_pair_market_history, pair_exchange_market_history, Exchange_name, pair, res.body)
554
+ rate_resolve({ pair, failed: false })
555
+ } else {
556
+ console.error(`getting market history ws failed for ${Exchange_name} ${pair}:`, res)
557
+ delete_pair_data(exchange_pair_market_history, pair_exchange_market_history, Exchange_name, pair)
558
+ track_ws_failure(ws_market_history_failed_pairs, Exchange_name, pair)
559
+ rate_resolve({ pair, failed: true })
560
+ }
561
+ })
537
562
  } else {
538
- console.error(`getting market history ws failed for ${Exchange_name} ${pair}:`, res)
539
- delete_pair_data(exchange_pair_market_history, pair_exchange_market_history, Exchange_name, pair)
540
- track_ws_failure(ws_market_history_failed_pairs, Exchange_name, pair)
541
- rate_resolve({ pair, failed: true })
563
+ // Pair not ready yet - check if we've exceeded timeout
564
+ const elapsed = Date.now() - pair_start_time
565
+ if (elapsed >= PAIR_READY_TIMEOUT_MS) {
566
+ // Timeout reached - mark as failed, will fall back to REST
567
+ console.log(`[WebSocket Market History] ${Exchange_name} ${pair}: Not ready after ${elapsed}ms (status: ${Exchange.ws.market.pair_status?.[pair] || 'unknown'})`)
568
+ rate_resolve({ pair, failed: true })
569
+ } else {
570
+ // Retry after a short delay
571
+ setTimeout(check_pair_ready, PAIR_CHECK_INTERVAL_MS)
572
+ }
542
573
  }
543
- })
574
+ }
575
+
576
+ // Start checking
577
+ check_pair_ready()
544
578
  })
545
579
  })
546
580
  Promise.all(market_history_promises)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icgio/icg-exchanges-wrapper",
3
- "version": "1.14.257",
3
+ "version": "1.14.259",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {