@watsonserve/stock-base 0.0.13 → 0.0.14

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 (3) hide show
  1. package/dao.js +17 -2
  2. package/package.json +1 -1
  3. package/types/dao.d.ts +10 -1
package/dao.js CHANGED
@@ -117,7 +117,7 @@ export class InfluxDAO {
117
117
  readStockLatest(ncs) {
118
118
  return this.__query(['c', 'v'], getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
119
119
  }
120
- async readDividend(ncs) {
120
+ async _readDividend(ncs) {
121
121
  const { origin: url, token, org, bucket } = this;
122
122
  const client = new InfluxDB({ url, token });
123
123
  const queryClient = client.getQueryApi(org);
@@ -136,8 +136,23 @@ export class InfluxDAO {
136
136
  list.unshift({ time: new Date(_time), nc, currency, [_field]: _value });
137
137
  },
138
138
  error: reject,
139
- complete: () => resolve(Object.entries(groupBy('nc', list, true))),
139
+ complete: () => resolve(groupBy('nc', list, true)),
140
140
  });
141
141
  });
142
142
  }
143
+ static ignore = new Set(['BRK.B']);
144
+ async readDividend(ncs) {
145
+ const divs = await this._readDividend(ncs);
146
+ // const none = ncs.filter(nc => !divs[nc]);
147
+ for (const nc of ncs) {
148
+ if (!divs[nc] && InfluxDAO.ignore.has(nc)) {
149
+ divs[nc] = [];
150
+ // none.push(nc);
151
+ }
152
+ }
153
+ return divs;
154
+ }
155
+ async writeNoRecord(nc) {
156
+ InfluxDAO.ignore.add(nc);
157
+ }
143
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
package/types/dao.d.ts CHANGED
@@ -18,6 +18,12 @@ interface IStData {
18
18
  c: number;
19
19
  v: number;
20
20
  }
21
+ interface IDiv {
22
+ time: Date;
23
+ nc: string;
24
+ currency: EnCurrency;
25
+ amount: number;
26
+ }
21
27
  export declare function toFxPoint(sgd: number, hkd: number, cny: number, timestamp: number): Point;
22
28
  export declare function toStockPoint(market: EnMarket, st: IStock, timestamp: number): Point;
23
29
  export declare function toDivPoints(market: string, nc: string, data: IDividend): Point[];
@@ -32,6 +38,9 @@ export declare class InfluxDAO {
32
38
  private __query;
33
39
  readFxLatest(): Promise<IFxData>;
34
40
  readStockLatest(ncs: string[]): Promise<IStData[]>;
35
- readDividend(ncs: string[]): Promise<[string, any[]][]>;
41
+ _readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
42
+ private static ignore;
43
+ readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
44
+ writeNoRecord(nc: string): Promise<void>;
36
45
  }
37
46
  export {};