bulltrackers-module 1.0.534 → 1.0.535
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.
|
@@ -27,17 +27,26 @@ async function fetchWithRetry(url, options, proxyManager, logger, label) {
|
|
|
27
27
|
if (res.ok) {
|
|
28
28
|
recordProxyOutcome(true);
|
|
29
29
|
return res;
|
|
30
|
+
} else {
|
|
31
|
+
// Log proxy failure with details
|
|
32
|
+
const errorText = await res.text().catch(() => 'Unable to read response');
|
|
33
|
+
logger.log('WARN', `[${label}] Proxy returned status ${res.status} for ${url}. Response: ${errorText.substring(0, 200)}`);
|
|
34
|
+
recordProxyOutcome(false);
|
|
30
35
|
}
|
|
31
36
|
} catch (e) {
|
|
32
37
|
recordProxyOutcome(false);
|
|
33
|
-
logger.log('WARN', `[${label}] Proxy failed. Retrying direct.`);
|
|
38
|
+
logger.log('WARN', `[${label}] Proxy failed for ${url}: ${e.message}. Retrying direct.`);
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
// Fallback
|
|
38
43
|
const directFetch = typeof fetch !== 'undefined' ? fetch : require('node-fetch');
|
|
39
44
|
const res = await directFetch(url, options);
|
|
40
|
-
if (!res.ok)
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const errorText = await res.text().catch(() => 'Unable to read response');
|
|
47
|
+
logger.log('ERROR', `[${label}] Direct fetch failed for ${url}: Status ${res.status}. Response: ${errorText.substring(0, 200)}`);
|
|
48
|
+
throw new Error(`Fetch failed: ${res.status} ${res.statusText} - ${errorText.substring(0, 100)}`);
|
|
49
|
+
}
|
|
41
50
|
return res;
|
|
42
51
|
}
|
|
43
52
|
|
|
@@ -57,6 +66,8 @@ async function processPortfolio(context, config, taskData, isPI) {
|
|
|
57
66
|
const { cid, username, uuid, today, requestOptions } = taskData;
|
|
58
67
|
const url = `${config.ETORO_API_PORTFOLIO_URL}?cid=${cid}&client_request_id=${uuid}`;
|
|
59
68
|
|
|
69
|
+
logger.log('INFO', `[Portfolio] Fetching ${isPI ? 'PI' : 'Signed-In User'} portfolio from: ${url}`);
|
|
70
|
+
|
|
60
71
|
const res = await fetchWithRetry(url, requestOptions, proxyManager, logger, 'Portfolio');
|
|
61
72
|
const data = await res.json();
|
|
62
73
|
data.fetchedAt = new Date();
|
|
@@ -438,7 +449,9 @@ async function handlePopularInvestorUpdate(taskData, config, dependencies) {
|
|
|
438
449
|
}
|
|
439
450
|
|
|
440
451
|
async function handleOnDemandUserUpdate(taskData, config, dependencies) {
|
|
441
|
-
|
|
452
|
+
// Use the same public portfolio endpoint as PIs - signed-in users can also use public endpoints
|
|
453
|
+
// The endpoint /sapi/portfolios/portfolio doesn't exist (404)
|
|
454
|
+
config.ETORO_API_PORTFOLIO_URL = config.ETORO_API_PORTFOLIO_URL || 'https://www.etoro.com/sapi/trade-data-real/live/public/portfolios';
|
|
442
455
|
config.ETORO_API_HISTORY_URL = config.ETORO_API_HISTORY_URL || 'https://www.etoro.com/sapi/trade-data-real/history/public/credit/flat';
|
|
443
456
|
|
|
444
457
|
return handleGenericUserUpdate(taskData, config, dependencies, false);
|