quote-observer 1.7.0 → 1.8.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.
Files changed (2) hide show
  1. package/cmd/ma.js +13 -9
  2. package/package.json +2 -2
package/cmd/ma.js CHANGED
@@ -9,7 +9,7 @@ const logger = require('../logger')();
9
9
  const Api = require('../api');
10
10
 
11
11
  // https://github.com/Marak/colors.js/blob/56de9f0983f68cd0a08c5b76d10a783e4b881716/lib/styles.js
12
- const codes = {
12
+ const styleCodes = {
13
13
  black: [30, 39],
14
14
  red: [31, 39],
15
15
  green: [32, 39],
@@ -22,7 +22,7 @@ const codes = {
22
22
  };
23
23
 
24
24
  function colors(string, name) {
25
- let [open, close] = codes[name];
25
+ let [open, close] = styleCodes[name];
26
26
  return `\u001b[${open}m${string}\u001b[${close}m`;
27
27
  }
28
28
 
@@ -98,8 +98,8 @@ function sale_signal(code, now) {
98
98
  return `[${srate}][${ceil(irate)}]`;
99
99
  }
100
100
 
101
- function start(codes) {
102
- let quotes = codes.map(code => Api.quote.kline_dayqfq(code, 10));
101
+ function start() {
102
+ let quotes = [...STOCKS_MAP.keys()].map(code => Api.quote.kline_dayqfq(code, 10));
103
103
  Promise.all(quotes).then(resps => {
104
104
  console.reset();
105
105
  console.log((new Date()).toTimeString().split(' ')[0]);
@@ -127,10 +127,10 @@ function start(codes) {
127
127
  console.log(rows.flat().join('\n'));
128
128
  console.log(LINE);
129
129
  if (errors.length) throw new Error('Errors occur.');
130
- setTimeout(() => start(codes), 10 * 1000);
130
+ setTimeout(() => start(), 10 * 1000);
131
131
  }).catch((error) => {
132
132
  logger.error(error.message);
133
- setTimeout(() => start(codes), 1 * 1000);
133
+ setTimeout(() => start(), 1 * 1000);
134
134
  });
135
135
  }
136
136
 
@@ -138,11 +138,11 @@ function market_match(stock, markets) {
138
138
  return markets.includes(String(stock.code).toUpperCase().split('.').shift());
139
139
  }
140
140
 
141
- module.exports = () => {
141
+ function update_stocks() {
142
142
  // SH,SZ,HK,US => [ 'SH', 'SZ', 'HK', 'US' ]
143
143
  const markets = String(global.config?.opts?.market || '').trim()
144
144
  .split(',').map(v => v.trim().toUpperCase()).filter(v => v);
145
- Promise.all([Api.futu.position(), Api.futu.following()]).then(([holders, follows]) => {
145
+ return Promise.all([Api.futu.position(), Api.futu.following()]).then(([holders, follows]) => {
146
146
  [
147
147
  ...Object.values(holders),
148
148
  follows,
@@ -150,6 +150,10 @@ module.exports = () => {
150
150
  .flat()
151
151
  .filter(stock => market_match(stock, markets))
152
152
  .forEach(stock => STOCKS_MAP.has(stock.code) || STOCKS_MAP.set(stock.code, stock));
153
- start([...STOCKS_MAP.keys()]);
154
153
  });
154
+ }
155
+
156
+ module.exports = () => {
157
+ update_stocks().then(() => start());
158
+ setInterval(update_stocks, 1 * 60 * 60 * 1000); // 1 hour
155
159
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quote-observer",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "quote observer",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -15,7 +15,7 @@
15
15
  "author": "kael",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "axios": "^0.21.0",
18
+ "axios": "^1.13.2",
19
19
  "commander": "^6.2.0",
20
20
  "rc": "^1.2.8"
21
21
  }