@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 -
|
|
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
|
-
//
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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 -
|
|
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
|
-
//
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
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)
|