daxiapi-cli 2.4.1 → 2.4.2
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/commands/market.js +17 -0
- package/lib/api.js +7 -2
- package/lib/dividendUtils.js +10 -3
- package/lib/output.js +4 -1
- package/package.json +1 -1
package/commands/market.js
CHANGED
|
@@ -31,7 +31,24 @@ module.exports = function (program) {
|
|
|
31
31
|
process.exit(1);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
+
marketCmd.command('compass')
|
|
35
|
+
.description('获取市场整合趋势结构、估值、情绪三层指标,用于A股市场三维结构分析系统,给出市场当前状态的综合判断与操作建议')
|
|
36
|
+
.action(async () => {
|
|
37
|
+
try {
|
|
38
|
+
const token = config.getToken();
|
|
39
|
+
if (!token) {
|
|
40
|
+
const error = new Error('未配置 API Token');
|
|
41
|
+
error.response = {status: 401};
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
34
44
|
|
|
45
|
+
const data = await api.getCompassData(token);
|
|
46
|
+
output(data);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
handleError(error);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
35
52
|
marketCmd
|
|
36
53
|
.command('temp')
|
|
37
54
|
.description(
|
package/lib/api.js
CHANGED
|
@@ -107,6 +107,10 @@ async function getSecId(token, code) {
|
|
|
107
107
|
const client = createClient(token);
|
|
108
108
|
return post(client, '/get_sec_id', {code});
|
|
109
109
|
}
|
|
110
|
+
async function getCompassData(token, ) {
|
|
111
|
+
const client = createClient(token);
|
|
112
|
+
return get(client, '/get_market_compass');
|
|
113
|
+
}
|
|
110
114
|
|
|
111
115
|
async function queryStockData(token, q, type = 'stock') {
|
|
112
116
|
const client = createClient(token);
|
|
@@ -146,8 +150,8 @@ async function getDividendScore(token, code) {
|
|
|
146
150
|
scores: recentScores.map(item => ({
|
|
147
151
|
date: item.date,
|
|
148
152
|
score: item.totalScore,
|
|
149
|
-
cs: item.cs.toFixed(2),
|
|
150
|
-
rsi: item.rsi.toFixed(2)
|
|
153
|
+
cs: item.cs != null ? item.cs.toFixed(2) : null,
|
|
154
|
+
rsi: item.rsi != null ? item.rsi.toFixed(2) : null
|
|
151
155
|
}))
|
|
152
156
|
};
|
|
153
157
|
}
|
|
@@ -441,6 +445,7 @@ async function getNewsReport(code, pageSize = 25, pageIndex = 1, beginTime = '20
|
|
|
441
445
|
module.exports = {
|
|
442
446
|
getMarketData,
|
|
443
447
|
getMarketTemp,
|
|
448
|
+
getCompassData,
|
|
444
449
|
getMarketStyle,
|
|
445
450
|
getMarketValueData,
|
|
446
451
|
getBkData,
|
package/lib/dividendUtils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const DIVIDEND_SCORE_CONSTANTS = {
|
|
2
2
|
ROLLING_WINDOW: 440,
|
|
3
|
-
PERCENTILE_LOW:
|
|
4
|
-
PERCENTILE_HIGH:
|
|
3
|
+
PERCENTILE_LOW: 0,
|
|
4
|
+
PERCENTILE_HIGH: 100,
|
|
5
5
|
SCORE_MA_PERIOD: 5,
|
|
6
6
|
EMA_PERIOD: 20,
|
|
7
7
|
MA_PERIOD: 80,
|
|
@@ -140,6 +140,7 @@ function calculateScores(data) {
|
|
|
140
140
|
|
|
141
141
|
const csValues = dataCopy.map(d => d.cs);
|
|
142
142
|
const ma80BiasValues = dataCopy.map(d => d.ma80Bias);
|
|
143
|
+
const rsiValues = dataCopy.map(d => d.rsi);
|
|
143
144
|
|
|
144
145
|
for (let i = 0; i < dataCopy.length; i++) {
|
|
145
146
|
const current = dataCopy[i];
|
|
@@ -155,6 +156,7 @@ function calculateScores(data) {
|
|
|
155
156
|
const startIdx = Math.max(0, i - DIVIDEND_SCORE_CONSTANTS.ROLLING_WINDOW + 1);
|
|
156
157
|
const csHistory = csValues.slice(startIdx, i + 1);
|
|
157
158
|
const ma80History = ma80BiasValues.slice(startIdx, i + 1);
|
|
159
|
+
const rsiHistory = rsiValues.slice(startIdx, i + 1);
|
|
158
160
|
|
|
159
161
|
current.csScore = calculateRollingScore(
|
|
160
162
|
current.cs,
|
|
@@ -168,7 +170,12 @@ function calculateScores(data) {
|
|
|
168
170
|
DIVIDEND_SCORE_CONSTANTS.PERCENTILE_LOW,
|
|
169
171
|
DIVIDEND_SCORE_CONSTANTS.PERCENTILE_HIGH
|
|
170
172
|
);
|
|
171
|
-
current.rsiScore =
|
|
173
|
+
current.rsiScore = calculateRollingScore(
|
|
174
|
+
current.rsi,
|
|
175
|
+
rsiHistory,
|
|
176
|
+
DIVIDEND_SCORE_CONSTANTS.PERCENTILE_LOW,
|
|
177
|
+
DIVIDEND_SCORE_CONSTANTS.PERCENTILE_HIGH
|
|
178
|
+
);
|
|
172
179
|
|
|
173
180
|
if (current.csScore !== null && current.ma80Score !== null && current.rsiScore !== null) {
|
|
174
181
|
current.totalScore = parseFloat(
|
package/lib/output.js
CHANGED
|
@@ -8,7 +8,10 @@ function output(data) {
|
|
|
8
8
|
console.log('[60]{"日期","分数","cs值","rsi值"}:');
|
|
9
9
|
|
|
10
10
|
data.scores.forEach(item => {
|
|
11
|
-
|
|
11
|
+
const score = item.score != null ? item.score : '-';
|
|
12
|
+
const cs = item.cs != null ? item.cs : '-';
|
|
13
|
+
const rsi = item.rsi != null ? item.rsi : '-';
|
|
14
|
+
console.log(` ${item.date},${score},${cs},${rsi}`);
|
|
12
15
|
});
|
|
13
16
|
|
|
14
17
|
console.log('```');
|