@fugle/node-twstock 3.0.0-alpha.0 → 3.0.0-alpha.1
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 +22 -6
- package/package.json +1 -1
|
@@ -350,7 +350,7 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
350
350
|
const url = `https://www.twse.com.tw/rwd/zh/exRight/TWT49UDetail?${query}`;
|
|
351
351
|
const response = await this.httpService.get(url);
|
|
352
352
|
const json = response.data.stat === 'ok' && response.data;
|
|
353
|
-
if (!json)
|
|
353
|
+
if (!json || !json.data || !json.data.length)
|
|
354
354
|
return null;
|
|
355
355
|
const [, name, ...values] = json.data[0];
|
|
356
356
|
const data = {};
|
|
@@ -469,7 +469,7 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
469
469
|
const url = `https://www.twse.com.tw/rwd/zh/reducation/TWTAVUDetail?${query}`;
|
|
470
470
|
const response = await this.httpService.get(url);
|
|
471
471
|
const json = response.data.stat === 'OK' && response.data;
|
|
472
|
-
if (!json)
|
|
472
|
+
if (!json || !json.data || !json.data.length)
|
|
473
473
|
return null;
|
|
474
474
|
const [, name, ...values] = json.data[0];
|
|
475
475
|
const data = {};
|
|
@@ -497,7 +497,7 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
497
497
|
const url = `https://www.twse.com.tw/rwd/zh/change/TWTB7UDetail?${query}`;
|
|
498
498
|
const response = await this.httpService.get(url);
|
|
499
499
|
const json = response.data.stat === 'OK' && response.data;
|
|
500
|
-
if (!json)
|
|
500
|
+
if (!json || !json.data || !json.data.length)
|
|
501
501
|
return null;
|
|
502
502
|
const [, name, ...values] = json.data[0];
|
|
503
503
|
const data = {};
|
|
@@ -632,7 +632,10 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
632
632
|
if (!json || !json.data)
|
|
633
633
|
return [];
|
|
634
634
|
const data = await Promise.all(json.data.map(async (row) => {
|
|
635
|
-
const [haltDate, symbol, name, resumeDate, splitRatio, oldFaceValue, newFaceValue
|
|
635
|
+
const [haltDate, symbol, name, resumeDate, splitRatio, oldFaceValue, newFaceValue, detailField1, // row[7]: "7780 ,20251230"
|
|
636
|
+
detailField2, // row[8]: "7780 ,20260109,20260119"
|
|
637
|
+
detailField3 // row[9]: ",10.00,1.00"
|
|
638
|
+
] = row;
|
|
636
639
|
const data = {};
|
|
637
640
|
data.symbol = symbol.trim();
|
|
638
641
|
data.name = name.trim();
|
|
@@ -642,12 +645,25 @@ class TwseScraper extends scraper_1.Scraper {
|
|
|
642
645
|
data.splitRatio = (0, utils_1.parseNumeric)(splitRatio);
|
|
643
646
|
data.oldFaceValue = (0, utils_1.parseNumeric)(oldFaceValue);
|
|
644
647
|
data.newFaceValue = (0, utils_1.parseNumeric)(newFaceValue);
|
|
648
|
+
// Extract detail query date from detailField1 (format: "symbol,date")
|
|
649
|
+
// Example: "7780 ,20251230" → extract "20251230"
|
|
650
|
+
let detailQueryDate;
|
|
651
|
+
if (detailField1) {
|
|
652
|
+
const parts = detailField1.split(',');
|
|
653
|
+
if (parts.length >= 2) {
|
|
654
|
+
const dateStr = parts[1].trim();
|
|
655
|
+
if (dateStr && dateStr.length === 8) {
|
|
656
|
+
// Convert YYYYMMDD to YYYY-MM-DD
|
|
657
|
+
detailQueryDate = `${dateStr.substring(0, 4)}-${dateStr.substring(4, 6)}-${dateStr.substring(6, 8)}`;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
645
661
|
// Include detail API call if requested (default: false for announcements)
|
|
646
|
-
if (includeDetail) {
|
|
662
|
+
if (includeDetail && detailQueryDate) {
|
|
647
663
|
try {
|
|
648
664
|
const detail = await this.fetchStocksSplitAnnouncementDetail({
|
|
649
665
|
symbol: data.symbol,
|
|
650
|
-
date:
|
|
666
|
+
date: detailQueryDate
|
|
651
667
|
});
|
|
652
668
|
return Object.assign(Object.assign({}, data), detail);
|
|
653
669
|
}
|