quote-observer 1.4.0 → 1.6.0

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/api/futu.js CHANGED
@@ -24,5 +24,5 @@ function apply(name) {
24
24
  });
25
25
  }
26
26
 
27
- exports.position = () => apply('position');
28
- exports.following = () => apply('following');
27
+ exports.position = () => global.config?.opts?.holder ? apply('position') : {};
28
+ exports.following = () => global.config?.opts?.follow ? apply('following') : [];
package/api/quote.js CHANGED
@@ -9,6 +9,7 @@
9
9
  // http://web.ifzq.gtimg.cn/appstock/app/hkfqkline/get?_var=kline_dayqfq&param=hk00700,day,,,10,qfq&r=0.283423356057471500
10
10
  // http://web.ifzq.gtimg.cn/appstock/app/fqkline/get?_var=kline_dayqfq&param=sz399006,day,,,10,qfq&r=0.4519900299757633000
11
11
 
12
+ const fs = require('fs');
12
13
  const axios = require('axios');
13
14
  const logger = require('../logger')();
14
15
  const querystring = require('querystring');
@@ -23,6 +24,20 @@ const path_mkt = {
23
24
 
24
25
  const fix_id = (id) => global.MARKET[id] || id;
25
26
 
27
+ // Storage response into file
28
+ const save_resp = (data) => {
29
+ try {
30
+ const root = global.config?.opts?.save;
31
+ if (root) {
32
+ fs.writeFileSync(`${root}/stock-quote-${data.fid}.json`, JSON.stringify(data));
33
+ }
34
+ } catch (error) {
35
+ logger.error(`Save resp error:`, error);
36
+ } finally {
37
+ return data;
38
+ }
39
+ };
40
+
26
41
  function kline_dayqfq(id, days = 10) {
27
42
  let [mkt, code] = id.split('.');
28
43
  if (!code) {
@@ -45,7 +60,7 @@ function kline_dayqfq(id, days = 10) {
45
60
  let resp = JSON.parse(raw.data.toString().replace(`${_var}=`, ''));
46
61
  let data = (resp || {}).data[_id] || [];
47
62
  let info = (data.qt || {})[_id] || [];
48
- return { fid: id, id: _id, info, data: (data.day || data.qfqday).reverse() };
63
+ return save_resp({ fid: id, id: _id, info, data: (data.day || data.qfqday || []).reverse() });
49
64
  } catch (error) {
50
65
  logger.error(id, error);
51
66
  return {};
package/cmd/ma.js CHANGED
@@ -134,16 +134,14 @@ function start(codes) {
134
134
  });
135
135
  }
136
136
 
137
- const args = (name) => {
138
- return ((global.config || {}).args || {})[name];
139
- };
140
-
141
137
  function market_match(stock, markets) {
142
138
  return markets.includes(String(stock.code).toUpperCase().split('.').shift());
143
139
  }
144
140
 
145
141
  module.exports = () => {
146
- const markets = args('market').map(v => v.toUpperCase());
142
+ // SH,SZ,HK,US => [ 'SH', 'SZ', 'HK', 'US' ]
143
+ const markets = String(global.config?.opts?.market || '').trim()
144
+ .split(',').map(v => v.trim().toUpperCase()).filter(v => v);
147
145
  Promise.all([Api.futu.position(), Api.futu.following()]).then(([holders, follows]) => {
148
146
  [
149
147
  ...Object.values(holders),
package/index.js CHANGED
@@ -12,16 +12,18 @@ global.config = require('rc')('stock');
12
12
  const { program } = require('commander');
13
13
  const pkg = require('./package.json');
14
14
  const cmd = require('./cmd');
15
- const mkt = `sh,sz,hk,us`;
16
-
17
- const split = v => v.toLowerCase().split(',');
18
15
 
19
16
  program
20
17
  .version(pkg.version)
21
- .option('-m, --market <items>', `Stock market (default ${mkt})`, split, split(mkt));
18
+ .option('-S, --save <root>', `save response into root`, '')
19
+ .option('-H, --holder', `show stock holder`, true)
20
+ .option(' --no-holder', `hide stock holder`)
21
+ .option('-F, --follow', `show stock follow`, false)
22
+ .option(' --no-follow', `hide stock follow`)
23
+ .option('-m, --market <items>', `stock market`, `sh,sz,hk,us`);
22
24
 
23
25
  program.parse(process.argv);
24
- global.config.args = program.opts();
26
+ global.config.opts = program.opts();
25
27
 
26
28
  // https://stackoverflow.com/questions/62499125/how-to-clear-terminal-and-scroll-back-in-nodejs
27
29
  console.reset = function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quote-observer",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "quote observer",
5
5
  "main": "index.js",
6
6
  "scripts": {