@watsonserve/stock-base 0.0.9 → 0.0.10
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 +9 -5
- package/package.json +1 -1
- package/types/dao.d.ts +15 -3
package/dao.js
CHANGED
|
@@ -100,7 +100,7 @@ export class InfluxDAO {
|
|
|
100
100
|
next: (row, tableMeta) => {
|
|
101
101
|
const item = tableMeta.toObject(row);
|
|
102
102
|
const { result, table, _start, _stop, _measurement, _time, nc, ...content } = item;
|
|
103
|
-
list.push({ time: new Date(_time),
|
|
103
|
+
list.push({ time: new Date(_time), nc, ...content });
|
|
104
104
|
},
|
|
105
105
|
error: reject,
|
|
106
106
|
complete: () => resolve(list),
|
|
@@ -109,12 +109,16 @@ export class InfluxDAO {
|
|
|
109
109
|
}
|
|
110
110
|
;
|
|
111
111
|
async readFxLatest() {
|
|
112
|
-
const
|
|
113
|
-
return
|
|
112
|
+
const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], getStartTime(), [EnMarket.FX], []);
|
|
113
|
+
return list[0];
|
|
114
114
|
}
|
|
115
115
|
async readStockLatest(ncs) {
|
|
116
|
-
const
|
|
117
|
-
return
|
|
116
|
+
const list = await this.__query(['c', 'v'], getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
|
|
117
|
+
return list.reduce((pre, item) => {
|
|
118
|
+
const { nc, ...data } = item;
|
|
119
|
+
pre[item.nc] = data;
|
|
120
|
+
return pre;
|
|
121
|
+
}, {});
|
|
118
122
|
}
|
|
119
123
|
async readDividend(ncs) {
|
|
120
124
|
const { origin: url, token, org, bucket } = this;
|
package/package.json
CHANGED
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<
|
|
22
|
-
readStockLatest(ncs: string[]): Promise<
|
|
32
|
+
readFxLatest(): Promise<IFxData>;
|
|
33
|
+
readStockLatest(ncs: string[]): Promise<Record<string, IStData>>;
|
|
23
34
|
readDividend(ncs: string[]): Promise<Record<string, any[]>>;
|
|
24
35
|
}
|
|
36
|
+
export {};
|