@watsonserve/stock-base 0.0.14 → 0.0.15
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 +12 -8
- package/package.json +1 -1
- package/types/dao.d.ts +2 -2
package/dao.js
CHANGED
|
@@ -2,14 +2,18 @@ import { InfluxDB, Point } from '@influxdata/influxdb-client';
|
|
|
2
2
|
import { request } from 'node:http';
|
|
3
3
|
import { EnCurrency, EnMarket } from './stock.js';
|
|
4
4
|
function getStartTime() {
|
|
5
|
-
|
|
5
|
+
const now = new Date();
|
|
6
|
+
let stamp = now.getTime() - 86400000;
|
|
7
|
+
switch (now.getUTCDay()) {
|
|
6
8
|
case 0: // Sunday
|
|
7
|
-
|
|
9
|
+
stamp -= 1 * 86400000;
|
|
10
|
+
break;
|
|
8
11
|
case 1:
|
|
9
|
-
|
|
12
|
+
stamp -= 2 * 86400000;
|
|
13
|
+
break;
|
|
10
14
|
default:
|
|
11
15
|
}
|
|
12
|
-
return
|
|
16
|
+
return new Date(stamp).toJSON().substring(0, 10);
|
|
13
17
|
}
|
|
14
18
|
export function toFxPoint(sgd, hkd, cny, timestamp) {
|
|
15
19
|
return new Point(EnMarket.FX)
|
|
@@ -110,12 +114,12 @@ export class InfluxDAO {
|
|
|
110
114
|
});
|
|
111
115
|
}
|
|
112
116
|
;
|
|
113
|
-
async readFxLatest() {
|
|
114
|
-
const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], getStartTime(), [EnMarket.FX], []);
|
|
117
|
+
async readFxLatest(start = '') {
|
|
118
|
+
const list = await this.__query([EnCurrency.SGD, EnCurrency.HKD, EnCurrency.CNY], start || getStartTime(), [EnMarket.FX], []);
|
|
115
119
|
return list[0];
|
|
116
120
|
}
|
|
117
|
-
readStockLatest(ncs) {
|
|
118
|
-
return this.__query(['c', 'v'], getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
|
|
121
|
+
readStockLatest(ncs, start = '') {
|
|
122
|
+
return this.__query(['c', 'v'], start || getStartTime(), [EnMarket.SGX, EnMarket.USA, EnMarket.HKEX], ncs);
|
|
119
123
|
}
|
|
120
124
|
async _readDividend(ncs) {
|
|
121
125
|
const { origin: url, token, org, bucket } = this;
|
package/package.json
CHANGED
package/types/dao.d.ts
CHANGED
|
@@ -36,8 +36,8 @@ export declare class InfluxDAO {
|
|
|
36
36
|
rm(measurement: string, start: string, stop: string): Promise<unknown>;
|
|
37
37
|
writeToInfluxDB(points: Point[]): Promise<void>;
|
|
38
38
|
private __query;
|
|
39
|
-
readFxLatest(): Promise<IFxData>;
|
|
40
|
-
readStockLatest(ncs: string[]): Promise<IStData[]>;
|
|
39
|
+
readFxLatest(start?: string): Promise<IFxData>;
|
|
40
|
+
readStockLatest(ncs: string[], start?: string): Promise<IStData[]>;
|
|
41
41
|
_readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
|
|
42
42
|
private static ignore;
|
|
43
43
|
readDividend(ncs: string[]): Promise<Record<string, IDiv[]>>;
|