@watsonserve/stock-base 0.0.16 → 0.0.17
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 +8 -6
- package/package.json +1 -1
- package/types/dao.d.ts +3 -3
package/dao.js
CHANGED
|
@@ -56,6 +56,7 @@ function groupBy(key, list, delKey = false) {
|
|
|
56
56
|
return pre;
|
|
57
57
|
}, {});
|
|
58
58
|
}
|
|
59
|
+
const A_DAY_MS = 86400000;
|
|
59
60
|
export class InfluxDAO {
|
|
60
61
|
origin = '';
|
|
61
62
|
org = '';
|
|
@@ -88,7 +89,7 @@ export class InfluxDAO {
|
|
|
88
89
|
await writeClient.flush();
|
|
89
90
|
await writeClient.close();
|
|
90
91
|
}
|
|
91
|
-
async
|
|
92
|
+
async __queryLatest(fileds, lt, markets, ncs) {
|
|
92
93
|
const { origin: url, token, org, bucket } = this;
|
|
93
94
|
const client = new InfluxDB({ url, token });
|
|
94
95
|
const queryClient = client.getQueryApi(org);
|
|
@@ -97,8 +98,9 @@ export class InfluxDAO {
|
|
|
97
98
|
const fdQuery = fileds.map(fd => `r["_field"] == "${fd}"`).join(' or ');
|
|
98
99
|
const filters = [mkQuery, ncQuery, fdQuery].filter(Boolean).map(str => `|> filter(fn: (r) => ${str})`).join('\n');
|
|
99
100
|
const fluxQuery = `from(bucket: "${bucket}")
|
|
100
|
-
|> range(start: ${
|
|
101
|
+
|> range(start: ${new Date(lt.getTime() - 30 * A_DAY_MS).toJSON().substring(0, 10)}, end: ${lt.toJSON()})
|
|
101
102
|
${filters}
|
|
103
|
+
|> last()
|
|
102
104
|
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`;
|
|
103
105
|
return new Promise((resolve, reject) => {
|
|
104
106
|
const list = [];
|
|
@@ -114,12 +116,12 @@ export class InfluxDAO {
|
|
|
114
116
|
});
|
|
115
117
|
}
|
|
116
118
|
;
|
|
117
|
-
async
|
|
118
|
-
const list = await this.
|
|
119
|
+
async readLatestFx(lt) {
|
|
120
|
+
const list = await this.__queryLatest([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], lt, [EnMarket.FX], []);
|
|
119
121
|
return list[0];
|
|
120
122
|
}
|
|
121
|
-
|
|
122
|
-
return this.
|
|
123
|
+
readLatestStock(ncs, lt) {
|
|
124
|
+
return this.__queryLatest(['c', 'v'], lt, [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
|
|
123
125
|
}
|
|
124
126
|
async _readDividend(ncs) {
|
|
125
127
|
const { origin: url, token, org, bucket } = this;
|
package/package.json
CHANGED
package/types/dao.d.ts
CHANGED
|
@@ -36,9 +36,9 @@ export declare class InfluxDAO {
|
|
|
36
36
|
constructor(dbConf: IDBConf);
|
|
37
37
|
rm(measurement: string, start: string, stop: string): Promise<unknown>;
|
|
38
38
|
writeToInfluxDB(points: Point[]): Promise<void>;
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
private __queryLatest;
|
|
40
|
+
readLatestFx(lt: Date): Promise<IFxData>;
|
|
41
|
+
readLatestStock(ncs: string[], lt: Date): Promise<IStData[]>;
|
|
42
42
|
_readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
|
|
43
43
|
private static ignore;
|
|
44
44
|
readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
|