@fugle/node-twstock 2.2.1-alpha.1 → 3.0.0-alpha.0
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.
- package/lib/scrapers/twse-scraper.js +15 -12
- package/package.json +1 -1
|
@@ -293,7 +293,7 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
293
293
|
return symbol ? data.find(data => data.symbol === symbol) : data;
|
|
294
294
|
}
|
|
295
295
|
async fetchStocksDividends(options) {
|
|
296
|
-
const { startDate, endDate, symbol, includeDetail =
|
|
296
|
+
const { startDate, endDate, symbol, includeDetail = false } = options;
|
|
297
297
|
const query = new URLSearchParams({
|
|
298
298
|
startDate: luxon_1.DateTime.fromISO(startDate).toFormat('yyyyMMdd'),
|
|
299
299
|
endDate: luxon_1.DateTime.fromISO(endDate).toFormat('yyyyMMdd'),
|
|
@@ -417,8 +417,8 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
417
417
|
return filterSymbol ? data.filter((item) => item.symbol === filterSymbol) : data;
|
|
418
418
|
}
|
|
419
419
|
async fetchStocksCapitalReductions(options) {
|
|
420
|
-
const { startDate, endDate, symbol } = options;
|
|
421
|
-
// Note:
|
|
420
|
+
const { startDate, endDate, symbol, includeDetail = false } = options;
|
|
421
|
+
// Note: Default false for performance, set true to include detail fields
|
|
422
422
|
const query = new URLSearchParams({
|
|
423
423
|
startDate: luxon_1.DateTime.fromISO(startDate).toFormat('yyyyMMdd'),
|
|
424
424
|
endDate: luxon_1.DateTime.fromISO(endDate).toFormat('yyyyMMdd'),
|
|
@@ -443,16 +443,19 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
443
443
|
data.openingReferencePrice = (0, utils_1.parseNumeric)(values[4]);
|
|
444
444
|
data.exrightReferencePrice = (0, utils_1.parseNumeric)(values[5]);
|
|
445
445
|
data.reason = values[6].trim();
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
446
|
+
if (includeDetail) {
|
|
447
|
+
try {
|
|
448
|
+
const [, detailDate] = values[7].split(',');
|
|
449
|
+
const detail = await this.fetchStockCapitalReductionDetail({ symbol, date: detailDate });
|
|
450
|
+
return Object.assign(Object.assign({}, data), detail);
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
// If detail fetch fails, return main data without detail
|
|
454
|
+
console.warn(`Failed to fetch capital reduction detail for ${symbol}:`, error);
|
|
455
|
+
return data;
|
|
456
|
+
}
|
|
455
457
|
}
|
|
458
|
+
return data;
|
|
456
459
|
}));
|
|
457
460
|
return symbol ? data.filter((data) => data.symbol === symbol) : data;
|
|
458
461
|
}
|