-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_api.html
More file actions
224 lines (197 loc) · 8.77 KB
/
Copy pathtest_api.html
File metadata and controls
224 lines (197 loc) · 8.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API测试 - FinLoom</title>
<style>
body {
font-family: 'Microsoft YaHei', Arial, sans-serif;
margin: 20px;
background: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
}
.section {
margin: 20px 0;
padding: 15px;
border: 1px solid #e0e0e0;
border-radius: 4px;
}
.section h2 {
margin-top: 0;
color: #1976d2;
}
.loading {
color: #666;
}
.success {
color: #4caf50;
}
.error {
color: #f44336;
}
pre {
background: #f8f8f8;
padding: 10px;
border-radius: 4px;
overflow-x: auto;
}
button {
background: #1976d2;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background: #1565c0;
}
</style>
</head>
<body>
<div class="container">
<h1>🧪 FinLoom API 测试页面</h1>
<div>
<button onclick="testAllAPIs()">🔄 测试所有API</button>
<button onclick="testSectorAPI()">📊 板块分析</button>
<button onclick="testSentimentAPI()">💭 市场情绪</button>
<button onclick="testIndicatorsAPI()">📈 技术指标</button>
<button onclick="testNewsAPI()">📰 市场资讯</button>
</div>
<div id="sectorSection" class="section">
<h2>1. 板块分析 API</h2>
<div id="sectorResult" class="loading">等待测试...</div>
</div>
<div id="sentimentSection" class="section">
<h2>2. 市场情绪 API</h2>
<div id="sentimentResult" class="loading">等待测试...</div>
</div>
<div id="indicatorsSection" class="section">
<h2>3. 技术指标 API</h2>
<div id="indicatorsResult" class="loading">等待测试...</div>
</div>
<div id="newsSection" class="section">
<h2>4. 市场资讯 API</h2>
<div id="newsResult" class="loading">等待测试...</div>
</div>
</div>
<script>
const API_BASE = 'http://localhost:8000';
async function testSectorAPI() {
const result = document.getElementById('sectorResult');
result.innerHTML = '<span class="loading">加载中...</span>';
try {
const response = await fetch(`${API_BASE}/api/v1/market/sector-analysis`);
const data = await response.json();
if (data.status === 'success' && data.data.sectors && data.data.sectors.length > 0) {
let html = '<div class="success">✅ 成功获取数据</div>';
html += `<p>共 ${data.data.sectors.length} 个板块</p>`;
html += '<h3>板块列表:</h3><ul>';
data.data.sectors.forEach(sector => {
const changeClass = sector.change >= 0 ? 'success' : 'error';
html += `<li><strong>${sector.name}</strong>: <span class="${changeClass}">${sector.change.toFixed(2)}%</span> (${sector.count}只股票)</li>`;
});
html += '</ul>';
html += `<details><summary>查看完整JSON</summary><pre>${JSON.stringify(data, null, 2)}</pre></details>`;
result.innerHTML = html;
} else {
result.innerHTML = '<div class="error">❌ 未获取到数据</div>';
}
} catch (error) {
result.innerHTML = `<div class="error">❌ 请求失败: ${error.message}</div>`;
}
}
async function testSentimentAPI() {
const result = document.getElementById('sentimentResult');
result.innerHTML = '<span class="loading">加载中...</span>';
try {
const response = await fetch(`${API_BASE}/api/v1/market/market-sentiment`);
const data = await response.json();
if (data.status === 'success') {
let html = '<div class="success">✅ 成功获取数据</div>';
html += `<p><strong>恐慌贪婪指数:</strong> ${data.data.fear_greed_index}</p>`;
html += `<p><strong>上涨股票:</strong> <span class="success">${data.data.advancing_stocks}</span></p>`;
html += `<p><strong>下跌股票:</strong> <span class="error">${data.data.declining_stocks}</span></p>`;
html += `<details><summary>查看完整JSON</summary><pre>${JSON.stringify(data, null, 2)}</pre></details>`;
result.innerHTML = html;
} else {
result.innerHTML = '<div class="error">❌ 未获取到数据</div>';
}
} catch (error) {
result.innerHTML = `<div class="error">❌ 请求失败: ${error.message}</div>`;
}
}
async function testIndicatorsAPI() {
const result = document.getElementById('indicatorsResult');
result.innerHTML = '<span class="loading">加载中...</span>';
try {
const response = await fetch(`${API_BASE}/api/v1/market/technical-indicators`);
const data = await response.json();
if (data.status === 'success' && data.data.indicators) {
let html = '<div class="success">✅ 成功获取数据</div>';
html += `<p>基于: ${data.data.based_on}</p>`;
html += '<h3>技术指标:</h3><ul>';
data.data.indicators.forEach(indicator => {
html += `<li><strong>${indicator.name}</strong>: ${indicator.value} (${indicator.signal})</li>`;
});
html += '</ul>';
html += `<details><summary>查看完整JSON</summary><pre>${JSON.stringify(data, null, 2)}</pre></details>`;
result.innerHTML = html;
} else {
result.innerHTML = '<div class="error">❌ 未获取到数据</div>';
}
} catch (error) {
result.innerHTML = `<div class="error">❌ 请求失败: ${error.message}</div>`;
}
}
async function testNewsAPI() {
const result = document.getElementById('newsResult');
result.innerHTML = '<span class="loading">加载中...</span>';
try {
const response = await fetch(`${API_BASE}/api/v1/market/market-news?limit=10`);
const data = await response.json();
if (data.status === 'success' && data.data.news) {
let html = '<div class="success">✅ 成功获取数据</div>';
html += `<p>共 ${data.data.news.length} 条资讯</p>`;
html += '<h3>资讯列表:</h3><ul>';
data.data.news.forEach(news => {
html += `<li><strong>${news.title}</strong><br>${news.summary.substring(0, 100)}...</li>`;
});
html += '</ul>';
html += `<details><summary>查看完整JSON</summary><pre>${JSON.stringify(data, null, 2)}</pre></details>`;
result.innerHTML = html;
} else {
result.innerHTML = '<div class="error">❌ 未获取到数据</div>';
}
} catch (error) {
result.innerHTML = `<div class="error">❌ 请求失败: ${error.message}</div>`;
}
}
async function testAllAPIs() {
await Promise.all([
testSectorAPI(),
testSentimentAPI(),
testIndicatorsAPI(),
testNewsAPI()
]);
}
// 页面加载时自动测试
window.addEventListener('load', () => {
console.log('页面加载完成,开始测试API...');
testAllAPIs();
});
</script>
</body>
</html>