@watsonserve/stock-base 0.0.10 → 0.0.11

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/dao.js CHANGED
@@ -41,11 +41,13 @@ export function toDivPoints(market, nc, data) {
41
41
  new Point('Dividend').tag('nc', `${nc}.${market}`).tag('type', 'paid').tag('currency', curr).floatField('amount', amount).timestamp(paid)
42
42
  ];
43
43
  }
44
- function groupBy(key, list) {
44
+ function groupBy(key, list, delKey = false) {
45
45
  return list.reduce((pre, item) => {
46
46
  const foo = item[key];
47
47
  const fooList = pre[foo] || [];
48
48
  pre[foo] = fooList;
49
+ if (delKey)
50
+ delete item[key];
49
51
  fooList.push(item);
50
52
  return pre;
51
53
  }, {});
@@ -112,13 +114,8 @@ export class InfluxDAO {
112
114
  const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], getStartTime(), [EnMarket.FX], []);
113
115
  return list[0];
114
116
  }
115
- async readStockLatest(ncs) {
116
- const list = await this.__query(['c', 'v'], getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
117
- return list.reduce((pre, item) => {
118
- const { nc, ...data } = item;
119
- pre[item.nc] = data;
120
- return pre;
121
- }, {});
117
+ readStockLatest(ncs) {
118
+ return this.__query(['c', 'v'], getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
122
119
  }
123
120
  async readDividend(ncs) {
124
121
  const { origin: url, token, org, bucket } = this;
@@ -140,7 +137,7 @@ export class InfluxDAO {
140
137
  },
141
138
  error: reject,
142
139
  complete: () => {
143
- resolve(groupBy('nc', list));
140
+ resolve(groupBy('nc', list, true));
144
141
  },
145
142
  });
146
143
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
package/types/dao.d.ts CHANGED
@@ -30,7 +30,7 @@ export declare class InfluxDAO {
30
30
  writeToInfluxDB(points: Point[]): Promise<void>;
31
31
  private __query;
32
32
  readFxLatest(): Promise<IFxData>;
33
- readStockLatest(ncs: string[]): Promise<Record<string, IStData>>;
33
+ readStockLatest(ncs: string[]): Promise<IStData[]>;
34
34
  readDividend(ncs: string[]): Promise<Record<string, any[]>>;
35
35
  }
36
36
  export {};