107 lines
4.1 KiB
Python
107 lines
4.1 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
测试web接口返回的分型强度数据
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import sys
|
|
import os
|
|
|
|
# 添加父目录到系统路径以便导入模块
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
def test_web_api():
|
|
"""测试web API接口返回的分型强度数据"""
|
|
|
|
print('=== 测试Web API分型强度数据 ===')
|
|
|
|
# 构建请求URL
|
|
base_url = "http://localhost:8123"
|
|
endpoint = "/api/analyze"
|
|
|
|
params = {
|
|
'symbol': 'SOL/USDT:USDT',
|
|
'timeframe': '5m',
|
|
'timezone': 'Asia/Shanghai'
|
|
}
|
|
|
|
try:
|
|
print(f"发送请求到: {base_url}{endpoint}")
|
|
print(f"参数: {params}")
|
|
|
|
# 发送请求
|
|
response = requests.get(f"{base_url}{endpoint}", params=params, timeout=30)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
|
|
# 检查是否有分型信息
|
|
if 'klc_fx_info' in data:
|
|
fx_info = data['klc_fx_info']
|
|
print(f"\n找到 {len(fx_info)} 个分型")
|
|
|
|
# 显示前3个分型的详细信息
|
|
for i, fx in enumerate(fx_info[:3]):
|
|
print(f"\n分型 #{i+1}:")
|
|
print(f" 时间: {fx.get('time', '无')}")
|
|
print(f" 价格: {fx.get('price', '无')}")
|
|
print(f" 分型类型: {fx.get('fx_type', '无')}")
|
|
print(f" 是否底分型: {fx.get('is_bottom', '无')}")
|
|
print(f" 强度分数: {fx.get('fx_strength', '缺失!')}")
|
|
print(f" 强度等级: {fx.get('fx_strength_level', '缺失!')}")
|
|
print(f" 是否强分型: {fx.get('is_strong_fx', '缺失!')}")
|
|
|
|
# 检查强度数据是否完整
|
|
missing_strength_count = 0
|
|
for fx in fx_info:
|
|
if 'fx_strength' not in fx or 'fx_strength_level' not in fx or 'is_strong_fx' not in fx:
|
|
missing_strength_count += 1
|
|
|
|
if missing_strength_count == 0:
|
|
print(f"\n✅ 所有 {len(fx_info)} 个分型都包含完整的强度数据")
|
|
else:
|
|
print(f"\n❌ 有 {missing_strength_count} 个分型缺少强度数据")
|
|
|
|
else:
|
|
print("\n❌ 响应中未找到分型信息 (klc_fx_info)")
|
|
|
|
# 检查小周期分型信息
|
|
if 'element_klc_fx_info' in data:
|
|
element_fx_info = data['element_klc_fx_info']
|
|
print(f"\n找到 {len(element_fx_info)} 个小周期分型")
|
|
|
|
# 检查小周期强度数据
|
|
missing_element_strength_count = 0
|
|
for fx in element_fx_info:
|
|
if 'fx_strength' not in fx or 'fx_strength_level' not in fx or 'is_strong_fx' not in fx:
|
|
missing_element_strength_count += 1
|
|
|
|
if missing_element_strength_count == 0:
|
|
print(f"✅ 所有 {len(element_fx_info)} 个小周期分型都包含完整的强度数据")
|
|
else:
|
|
print(f"❌ 有 {missing_element_strength_count} 个小周期分型缺少强度数据")
|
|
|
|
else:
|
|
print(f"❌ 请求失败,状态码: {response.status_code}")
|
|
print(f"响应内容: {response.text}")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ 无法连接到服务器,请确保web服务正在运行 (python web/app.py)")
|
|
except Exception as e:
|
|
print(f"❌ 测试过程中出错: {e}")
|
|
|
|
def print_usage():
|
|
"""打印使用说明"""
|
|
print("\n=== 使用说明 ===")
|
|
print("1. 确保web服务正在运行:")
|
|
print(" cd user_data/Chan/web")
|
|
print(" python app.py")
|
|
print("\n2. 然后运行此测试脚本:")
|
|
print(" python test_web_data.py")
|
|
print("\n3. 检查控制台输出,确认分型强度数据是否正确返回")
|
|
|
|
if __name__ == "__main__":
|
|
test_web_api()
|
|
print_usage() |