@watsonserve/stock-base 0.0.27 → 0.0.28

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.
Files changed (2) hide show
  1. package/dividend-loader.js +14 -7
  2. package/package.json +1 -1
@@ -11,6 +11,16 @@ function toDivPoint(fullNc, div) {
11
11
  paid: ~~(paid.getTime() / 1000)
12
12
  };
13
13
  }
14
+ const rxDate = /\d+/g;
15
+ function dateCNtoDate(str) {
16
+ const ymd = str.match(rxDate)?.slice(0, 3).map(i => +i);
17
+ if (!ymd)
18
+ return null;
19
+ if ('number' === typeof ymd?.[1]) {
20
+ ymd[1] -= 1;
21
+ }
22
+ return new Date(Date.UTC.apply(null, ymd));
23
+ }
14
24
  export class DividendLoader extends PriceLoader {
15
25
  async __laodIbmCode(nc) {
16
26
  const resp = await super.get(`https://api.sgx.com/marketmetadata/v2?stock-code=${nc}`);
@@ -27,19 +37,16 @@ export class DividendLoader extends PriceLoader {
27
37
  const list = [];
28
38
  for (const item of entitlementlist) {
29
39
  const { detail, announcement_date, ex_date, payment_date, announcement_URL } = item;
40
+ const annc = dateCNtoDate(announcement_date);
41
+ const ex = dateCNtoDate(ex_date);
42
+ const paid = dateCNtoDate(payment_date);
30
43
  const divid = Array.from(detail.match(/(USD|HKD|GBP) (\d+\.\d+)/g) || [])
31
44
  .reduce((pre, item) => {
32
45
  const [currency, amount] = item.split(' ');
33
46
  pre[currency] = { currency, amount: +amount };
34
47
  return pre;
35
48
  }, {});
36
- list.push({
37
- ...(divid['HKD'] || divid['USD'] || divid['GBP']),
38
- annc: new Date(announcement_date.substring(0, 10)),
39
- ex: new Date(ex_date.substring(0, 10)),
40
- paid: new Date(payment_date.substring(0, 10)),
41
- announcement_URL
42
- });
49
+ list.push({ ...(divid['HKD'] || divid['USD'] || divid['GBP']), annc, ex, paid, announcement_URL });
43
50
  }
44
51
  return [ttm('ex', list), []];
45
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.js",