@watsonserve/stock-loader 0.0.2-alpha.0 → 0.0.2-alpha.1
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/package.json +1 -1
- package/src/history-loader.ts +8 -7
package/package.json
CHANGED
package/src/history-loader.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EnMarket } from '@watsonserve/stock-base';
|
|
1
|
+
import { EnMarket, type StockPoint } from '@watsonserve/stock-base';
|
|
2
2
|
import { getMarketCloseTime } from './close-time.js';
|
|
3
3
|
import WebRequest from './web-request.js';
|
|
4
4
|
import { sleep, splitFullNc } from './helper.js';
|
|
5
5
|
|
|
6
6
|
// 历史数据
|
|
7
7
|
export default class HistoryLoader extends WebRequest {
|
|
8
|
-
private async __getHKOrUSAHistory(market: EnMarket, nc: string) {
|
|
8
|
+
private async __getHKOrUSAHistory(market: EnMarket, nc: string): Promise<StockPoint[]> {
|
|
9
9
|
let cntry = EnMarket.USA === market ? 'us' : 'hk';
|
|
10
10
|
await this.goto(`https://quote.eastmoney.com/${cntry}/${nc}.html`);
|
|
11
11
|
|
|
@@ -36,13 +36,14 @@ export default class HistoryLoader extends WebRequest {
|
|
|
36
36
|
return (klines as string[]).map(line => {
|
|
37
37
|
const [date, open, close, hight, low, vol] = line.split(',');
|
|
38
38
|
return {
|
|
39
|
-
market,
|
|
40
|
-
|
|
39
|
+
market,
|
|
40
|
+
timestamp: getMarketCloseTime(market, new Date(`${date}T15:00:00Z`).getTime()),
|
|
41
|
+
st: { nc, n: '', o:+open, c:+close, h:+hight, l:+low, v:+vol }
|
|
41
42
|
};
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
private async __getSGXHistory(nc: string) {
|
|
46
|
+
private async __getSGXHistory(nc: string): Promise<StockPoint[]> {
|
|
46
47
|
const rsp = await super.get(`https://api.sgx.com/securities/v1.1//charts/historic/stocks/code/${nc}/5y`, { params: 'trading_time,vl,lt' });
|
|
47
48
|
const { historic } = rsp.data;
|
|
48
49
|
return (historic as any[]).map(st => {
|
|
@@ -50,8 +51,8 @@ export default class HistoryLoader extends WebRequest {
|
|
|
50
51
|
const fullYear = trading_time.substring(0, 4);
|
|
51
52
|
const month = trading_time.substring(4, 6);
|
|
52
53
|
const date = trading_time.substring(6, 8);
|
|
53
|
-
const
|
|
54
|
-
return { market: EnMarket.SGX, nc, n: '', o: 0, c, h: 0, l: 0, v
|
|
54
|
+
const timestamp = ~~(new Date(`${fullYear}-${month}-${date}T09:16:00Z`).getTime() / 1000);
|
|
55
|
+
return { market: EnMarket.SGX, timestamp, st: { nc, n: '', o: 0, c, h: 0, l: 0, v } };
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
|