quote-observer 2.0.2 → 2.0.3
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/core.js +10 -1
- package/index.js +1 -0
- package/package.json +1 -1
- package/services/kline.js +9 -3
package/core.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @Last Modified time: 2021-11-09 10:43:03
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
const fs = require('fs');
|
|
8
9
|
const logger = require('./logger')();
|
|
9
10
|
const Futu = require('./services/futu');
|
|
10
11
|
const KLine = require('./services/kline');
|
|
@@ -107,7 +108,7 @@ function random_delay() {
|
|
|
107
108
|
}
|
|
108
109
|
|
|
109
110
|
function start() {
|
|
110
|
-
const quotes = [...STOCKS_MAP.keys()].map(code => random_delay().then(() => KLine(code, 10)));
|
|
111
|
+
const quotes = [...STOCKS_MAP.keys()].map(code => random_delay().then(() => KLine(code, 10, STOCKS_MAP.get(code)?.tid)));
|
|
111
112
|
Promise.all(quotes).then(resps => {
|
|
112
113
|
console.reset();
|
|
113
114
|
console.log((new Date()).toTimeString().split(' ')[0]);
|
|
@@ -149,6 +150,14 @@ function update_stocks() {
|
|
|
149
150
|
// SH,SZ,HK,US => [ 'SH', 'SZ', 'HK', 'US' ]
|
|
150
151
|
const markets = String(global.config?.opts?.market || '').trim()
|
|
151
152
|
.split(',').map(v => v.trim().toUpperCase()).filter(v => v);
|
|
153
|
+
const codes = global.config?.opts?.codes;
|
|
154
|
+
if (codes && fs.existsSync(codes)) {
|
|
155
|
+
fs.readFileSync(codes, 'utf8').toString().trim().split('\n').map(v => {
|
|
156
|
+
const stock = JSON.parse(v.trim());
|
|
157
|
+
STOCKS_MAP.set(stock.code, stock);
|
|
158
|
+
});
|
|
159
|
+
return Promise.resolve();
|
|
160
|
+
}
|
|
152
161
|
return Promise.all([Futu.position(), Futu.following()]).then(([holders, follows]) => {
|
|
153
162
|
STOCKS_MAP.clear();
|
|
154
163
|
[
|
package/index.js
CHANGED
|
@@ -15,6 +15,7 @@ const pkg = require('./package.json');
|
|
|
15
15
|
program
|
|
16
16
|
.version(pkg.version)
|
|
17
17
|
.option('-S, --save <root>', `save response into root`, '')
|
|
18
|
+
.option('-C, --codes <root>', `load codes from file`, '')
|
|
18
19
|
.option('-H, --holder', `show stock holder`, true)
|
|
19
20
|
.option(' --no-holder', `hide stock holder`)
|
|
20
21
|
.option('-F, --follow', `show stock follow`, false)
|
package/package.json
CHANGED
package/services/kline.js
CHANGED
|
@@ -39,13 +39,19 @@ const save_resp = (data) => {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
const convert2tid = (mkt, code, tid) => {
|
|
43
|
+
if (tid) return tid;
|
|
44
|
+
if (!code) return '';
|
|
45
|
+
return fix_id(`${mkt.toLowerCase()}${code}${'US' === mkt ? '.OQ' : ''}`);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function kline(id, days = 10, tid = '') {
|
|
43
49
|
const [mkt, code] = id.split('.');
|
|
44
|
-
|
|
50
|
+
const _id = convert2tid(mkt, code, tid);
|
|
51
|
+
if (!_id) {
|
|
45
52
|
logger.info(`[${id}] INDEX SKIP`);
|
|
46
53
|
return {};
|
|
47
54
|
}
|
|
48
|
-
const _id = fix_id(`${mkt.toLowerCase()}${code}${'US' === mkt ? '.OQ' : ''}`);
|
|
49
55
|
const _var = 'kline_dayqfq';
|
|
50
56
|
const params = {
|
|
51
57
|
_var,
|