@watsonserve/stock-base 0.0.10 → 0.0.12
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 +6 -9
- package/package.json +1 -1
- package/types/dao.d.ts +2 -1
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
|
-
|
|
116
|
-
|
|
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
package/types/dao.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ interface IFxData {
|
|
|
14
14
|
}
|
|
15
15
|
interface IStData {
|
|
16
16
|
time: string;
|
|
17
|
+
nc: string;
|
|
17
18
|
c: number;
|
|
18
19
|
v: number;
|
|
19
20
|
}
|
|
@@ -30,7 +31,7 @@ export declare class InfluxDAO {
|
|
|
30
31
|
writeToInfluxDB(points: Point[]): Promise<void>;
|
|
31
32
|
private __query;
|
|
32
33
|
readFxLatest(): Promise<IFxData>;
|
|
33
|
-
readStockLatest(ncs: string[]): Promise<
|
|
34
|
+
readStockLatest(ncs: string[]): Promise<IStData[]>;
|
|
34
35
|
readDividend(ncs: string[]): Promise<Record<string, any[]>>;
|
|
35
36
|
}
|
|
36
37
|
export {};
|