84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
"""
|
|
龙回头选股器测试脚本
|
|
运行: cd backend && python ../tests/test_pullback_selector.py
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# 添加 backend 目录到 Python 路径
|
|
backend_dir = Path(__file__).parent.parent / "backend"
|
|
sys.path.insert(0, str(backend_dir))
|
|
|
|
# 切换到 backend 目录(确保 .env 能被找到)
|
|
os.chdir(backend_dir)
|
|
|
|
from app.config import get_settings
|
|
from app.astock_agent.pullback_selector import get_pullback_selector
|
|
import logging
|
|
|
|
# 启用详细日志
|
|
logging.getLogger('stock_agent').setLevel(logging.DEBUG)
|
|
|
|
|
|
async def test_pullback_selector():
|
|
"""测试龙回头选股器"""
|
|
print("=" * 60)
|
|
print("龙回头选股器测试")
|
|
print("=" * 60)
|
|
|
|
settings = get_settings()
|
|
print(f"\n配置:")
|
|
print(f" Tushare Token: {'已配置' if settings.tushare_token else '未配置'}")
|
|
print(f" 选股启用: {settings.pullback_selector_enabled}")
|
|
print(f" 检查板块数: {settings.pullback_sectors_to_check}")
|
|
|
|
if not settings.tushare_token:
|
|
print("\n❌ 错误: 请先在 .env 中配置 TUSHARE_TOKEN")
|
|
return
|
|
|
|
# 创建选股器
|
|
selector = get_pullback_selector()
|
|
|
|
print(f"\n开始选股...")
|
|
print(f"检查板块数: {settings.pullback_sectors_to_check}")
|
|
print(f"每个板块最多选: 2 只\n")
|
|
|
|
# 执行选股
|
|
results = selector.select_from_hot_sectors(top_n=settings.pullback_sectors_to_check)
|
|
|
|
# 显示结果
|
|
if results:
|
|
print("\n" + "=" * 60)
|
|
print("选股结果")
|
|
print("=" * 60)
|
|
|
|
for sector_name, stocks in results.items():
|
|
print(f"\n【{sector_name}】")
|
|
for stock in stocks:
|
|
print(f" 📈 {stock['name']}({stock['ts_code']})")
|
|
print(f" 现价: ¥{stock['close']:.2f} | 回踩: {stock['pullback_pct']:.2f}% | 涨幅: {stock['rise_pct']:.2f}%")
|
|
print(f" MA5: ¥{stock['ma5']:.2f} | MA10: ¥{stock['ma10']:.2f} | MA30: ¥{stock['ma30']:.2f} | MA60: ¥{stock['ma60']:.2f}")
|
|
print(f" 缩量比: {stock['volume_shrink_ratio']:.0%} | 再放量: {stock['recent_volume_ratio']:.2f}x")
|
|
|
|
total = sum(len(stocks) for stocks in results.values())
|
|
print(f"\n共选出 {total} 只股票")
|
|
|
|
# 格式化完整消息
|
|
print("\n" + "=" * 60)
|
|
print("通知消息预览")
|
|
print("=" * 60)
|
|
print(selector.format_result(results))
|
|
|
|
else:
|
|
print("\n未选出符合条件的股票")
|
|
|
|
print("\n" + "=" * 60)
|
|
print("测试完成")
|
|
print("=" * 60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_pullback_selector())
|