@watsonserve/stock-base 0.0.15 → 0.0.16
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 +7 -7
- package/package.json +1 -1
- package/types/dao.d.ts +3 -2
package/dao.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InfluxDB, Point } from '@influxdata/influxdb-client';
|
|
2
2
|
import { request } from 'node:http';
|
|
3
3
|
import { EnCurrency, EnMarket } from './stock.js';
|
|
4
|
-
function
|
|
4
|
+
export function latestDay() {
|
|
5
5
|
const now = new Date();
|
|
6
6
|
let stamp = now.getTime() - 86400000;
|
|
7
7
|
switch (now.getUTCDay()) {
|
|
@@ -88,7 +88,7 @@ export class InfluxDAO {
|
|
|
88
88
|
await writeClient.flush();
|
|
89
89
|
await writeClient.close();
|
|
90
90
|
}
|
|
91
|
-
async __query(fileds,
|
|
91
|
+
async __query(fileds, duration, markets, ncs) {
|
|
92
92
|
const { origin: url, token, org, bucket } = this;
|
|
93
93
|
const client = new InfluxDB({ url, token });
|
|
94
94
|
const queryClient = client.getQueryApi(org);
|
|
@@ -97,7 +97,7 @@ export class InfluxDAO {
|
|
|
97
97
|
const fdQuery = fileds.map(fd => `r["_field"] == "${fd}"`).join(' or ');
|
|
98
98
|
const filters = [mkQuery, ncQuery, fdQuery].filter(Boolean).map(str => `|> filter(fn: (r) => ${str})`).join('\n');
|
|
99
99
|
const fluxQuery = `from(bucket: "${bucket}")
|
|
100
|
-
|> range(start: ${
|
|
100
|
+
|> range(start: ${duration[0]}, end: ${duration[1]})
|
|
101
101
|
${filters}
|
|
102
102
|
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")`;
|
|
103
103
|
return new Promise((resolve, reject) => {
|
|
@@ -114,12 +114,12 @@ export class InfluxDAO {
|
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
116
|
;
|
|
117
|
-
async
|
|
118
|
-
const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY],
|
|
117
|
+
async readFx(duration) {
|
|
118
|
+
const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], duration, [EnMarket.FX], []);
|
|
119
119
|
return list[0];
|
|
120
120
|
}
|
|
121
|
-
|
|
122
|
-
return this.__query(['c', 'v'],
|
|
121
|
+
readStock(ncs, duration) {
|
|
122
|
+
return this.__query(['c', 'v'], duration, [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
|
|
123
123
|
}
|
|
124
124
|
async _readDividend(ncs) {
|
|
125
125
|
const { origin: url, token, org, bucket } = this;
|
package/package.json
CHANGED
package/types/dao.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ interface IDiv {
|
|
|
24
24
|
currency: EnCurrency;
|
|
25
25
|
amount: number;
|
|
26
26
|
}
|
|
27
|
+
export declare function latestDay(): string;
|
|
27
28
|
export declare function toFxPoint(sgd: number, hkd: number, cny: number, timestamp: number): Point;
|
|
28
29
|
export declare function toStockPoint(market: EnMarket, st: IStock, timestamp: number): Point;
|
|
29
30
|
export declare function toDivPoints(market: string, nc: string, data: IDividend): Point[];
|
|
@@ -36,8 +37,8 @@ export declare class InfluxDAO {
|
|
|
36
37
|
rm(measurement: string, start: string, stop: string): Promise<unknown>;
|
|
37
38
|
writeToInfluxDB(points: Point[]): Promise<void>;
|
|
38
39
|
private __query;
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
readFx(duration: string[]): Promise<IFxData>;
|
|
41
|
+
readStock(ncs: string[], duration: string[]): Promise<IStData[]>;
|
|
41
42
|
_readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
|
|
42
43
|
private static ignore;
|
|
43
44
|
readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
|