@fugle/node-twstock 2.2.1-alpha.0 → 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.
@@ -49,14 +49,6 @@ export declare class TwseScraper extends Scraper {
49
49
  symbol: string;
50
50
  date: string;
51
51
  }): Promise<Record<string, any> | null>;
52
- fetchStocksDividendsAnnouncementDetail(options: {
53
- date: string;
54
- symbol: string;
55
- }): Promise<Record<string, any> | null>;
56
- fetchStocksCapitalReductionAnnouncementDetail(options: {
57
- symbol: string;
58
- date: string;
59
- }): Promise<Record<string, any> | null>;
60
52
  fetchStocksSplitAnnouncementDetail(options: {
61
53
  symbol: string;
62
54
  date: string;
@@ -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 = true } = options;
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'),
@@ -400,7 +400,7 @@ class TwseScraper extends scraper_1.Scraper {
400
400
  // Include detail API call if requested (default: false for announcements)
401
401
  if (includeDetail) {
402
402
  try {
403
- const detail = await this.fetchStocksDividendsAnnouncementDetail({
403
+ const detail = await this.fetchStocksDividendsDetail({
404
404
  symbol: data.symbol,
405
405
  date: data.exdividendDate
406
406
  });
@@ -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: Always fetch detail for consistency with TPEx, includeDetail parameter is ignored
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,68 +443,23 @@ 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
- try {
447
- const [, detailDate] = values[7].split(',');
448
- const detail = await this.fetchStockCapitalReductionDetail({ symbol, date: detailDate });
449
- return Object.assign(Object.assign({}, data), detail);
450
- }
451
- catch (error) {
452
- // If detail fetch fails, return main data without detail
453
- console.warn(`Failed to fetch capital reduction detail for ${symbol}:`, error);
454
- return data;
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
  }
459
462
  async fetchStockCapitalReductionDetail(options) {
460
- const { date, symbol } = options;
461
- const query = new URLSearchParams({
462
- STK_NO: symbol,
463
- FILE_DATE: luxon_1.DateTime.fromISO(date).toFormat('yyyyMMdd'),
464
- response: 'json',
465
- });
466
- const url = `https://www.twse.com.tw/rwd/zh/reducation/TWTAVUDetail?${query}`;
467
- const response = await this.httpService.get(url);
468
- const json = response.data.stat === 'OK' && response.data;
469
- if (!json)
470
- return null;
471
- const [, name, ...values] = json.data[0];
472
- const data = {};
473
- data.symbol = symbol;
474
- data.name = name.trim();
475
- data.haltDate = (0, utils_1.rocToWestern)(values[0]);
476
- data.sharesPerThousand = (0, utils_1.parseNumeric)(values[1]);
477
- data.refundPerShare = (0, utils_1.parseNumeric)(values[2]);
478
- return data;
479
- }
480
- async fetchStocksDividendsAnnouncementDetail(options) {
481
- const { date, symbol } = options;
482
- const query = new URLSearchParams({
483
- STK_NO: symbol,
484
- T1: luxon_1.DateTime.fromISO(date).toFormat('yyyyMMdd'),
485
- response: 'json',
486
- });
487
- const url = `https://www.twse.com.tw/rwd/zh/exRight/TWT49UDetail?${query}`;
488
- const response = await this.httpService.get(url);
489
- const json = response.data.stat === 'ok' && response.data;
490
- if (!json)
491
- return null;
492
- const [, name, ...values] = json.data[0];
493
- const data = {};
494
- data.symbol = symbol;
495
- data.name = name.trim();
496
- data.cashDividend = (0, utils_1.parseNumeric)(values[0]);
497
- data.stockDividendShares = (0, utils_1.parseNumeric)(values[2]);
498
- data.employeeBonusShares = (0, utils_1.parseNumeric)(values[3]);
499
- data.paidCapitalIncrease = (0, utils_1.parseNumeric)(values[4]);
500
- data.subscriptionPrice = (0, utils_1.parseNumeric)(values[5]);
501
- data.publicOffering = (0, utils_1.parseNumeric)(values[6]);
502
- data.employeeSubscription = (0, utils_1.parseNumeric)(values[7]);
503
- data.existingShareholderSubscription = (0, utils_1.parseNumeric)(values[8]);
504
- data.sharesPerThousand = (0, utils_1.parseNumeric)(values[9]);
505
- return data;
506
- }
507
- async fetchStocksCapitalReductionAnnouncementDetail(options) {
508
463
  const { date, symbol } = options;
509
464
  const query = new URLSearchParams({
510
465
  STK_NO: symbol,
@@ -582,7 +537,7 @@ class TwseScraper extends scraper_1.Scraper {
582
537
  // Include detail API call if requested (default: false for announcements)
583
538
  if (includeDetail) {
584
539
  try {
585
- const detail = await this.fetchStocksCapitalReductionAnnouncementDetail({
540
+ const detail = await this.fetchStockCapitalReductionDetail({
586
541
  symbol: data.symbol,
587
542
  date: data.haltDate
588
543
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fugle/node-twstock",
3
- "version": "2.2.1-alpha.0",
3
+ "version": "3.0.0-alpha.0",
4
4
  "description": "A client library for scraping Taiwan stock market data",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",