@watsonserve/stock-base 0.0.9 → 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.
Files changed (3) hide show
  1. package/dao.js +9 -8
  2. package/package.json +1 -1
  3. package/types/dao.d.ts +15 -3
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
  }, {});
@@ -100,7 +102,7 @@ export class InfluxDAO {
100
102
  next: (row, tableMeta) => {
101
103
  const item = tableMeta.toObject(row);
102
104
  const { result, table, _start, _stop, _measurement, _time, nc, ...content } = item;
103
- list.push({ time: new Date(_time), market: _measurement, nc, ...content });
105
+ list.push({ time: new Date(_time), nc, ...content });
104
106
  },
105
107
  error: reject,
106
108
  complete: () => resolve(list),
@@ -109,12 +111,11 @@ export class InfluxDAO {
109
111
  }
110
112
  ;
111
113
  async readFxLatest() {
112
- const start = getStartTime();
113
- return this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], start, [EnMarket.FX], []);
114
+ const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], getStartTime(), [EnMarket.FX], []);
115
+ return list[0];
114
116
  }
115
- async readStockLatest(ncs) {
116
- const start = getStartTime();
117
- return this.__query(['c', 'v'], start, [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
117
+ readStockLatest(ncs) {
118
+ return this.__query(['c', 'v'], getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
118
119
  }
119
120
  async readDividend(ncs) {
120
121
  const { origin: url, token, org, bucket } = this;
@@ -136,7 +137,7 @@ export class InfluxDAO {
136
137
  },
137
138
  error: reject,
138
139
  complete: () => {
139
- resolve(groupBy('nc', list));
140
+ resolve(groupBy('nc', list, true));
140
141
  },
141
142
  });
142
143
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watsonserve/stock-base",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "keywords": [],
package/types/dao.d.ts CHANGED
@@ -1,11 +1,22 @@
1
1
  import { Point } from '@influxdata/influxdb-client';
2
- import { EnMarket, IDividend, type IStock } from './stock.js';
2
+ import { EnCurrency, EnMarket, IDividend, type IStock } from './stock.js';
3
3
  export interface IDBConf {
4
4
  origin: string;
5
5
  org: string;
6
6
  bucket: string;
7
7
  token: string;
8
8
  }
9
+ interface IFxData {
10
+ time: string;
11
+ [EnCurrency.SGD]: number;
12
+ [EnCurrency.HKD]: number;
13
+ [EnCurrency.CNY]: number;
14
+ }
15
+ interface IStData {
16
+ time: string;
17
+ c: number;
18
+ v: number;
19
+ }
9
20
  export declare function toFxPoint(sgd: number, hkd: number, cny: number, timestamp: number): Point;
10
21
  export declare function toStockPoint(market: EnMarket, st: IStock, timestamp: number): Point;
11
22
  export declare function toDivPoints(market: string, nc: string, data: IDividend): Point[];
@@ -18,7 +29,8 @@ export declare class InfluxDAO {
18
29
  rm(measurement: string, start: string, stop: string): Promise<unknown>;
19
30
  writeToInfluxDB(points: Point[]): Promise<void>;
20
31
  private __query;
21
- readFxLatest(): Promise<any[]>;
22
- readStockLatest(ncs: string[]): Promise<any[]>;
32
+ readFxLatest(): Promise<IFxData>;
33
+ readStockLatest(ncs: string[]): Promise<IStData[]>;
23
34
  readDividend(ncs: string[]): Promise<Record<string, any[]>>;
24
35
  }
36
+ export {};