主要功能: - K线形态策略: 两阳+阴+阳突破形态识别 - 信号时间修复: 使用K线时间而非发送时间 - 换手率约束: 最后阳线换手率不超过40% - 汇总通知: 钉钉webhook单次发送所有信号 - 数据获取: 支持AKShare数据源 - 舆情分析: 北向资金、热门股票等 技术特性: - 支持日线/周线/月线多时间周期 - EMA20趋势确认 - 实体比例验证 - 突破价格确认 - 流动性约束检查 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
135 lines
4.8 KiB
Python
135 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
舆情数据功能测试脚本
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# 将src目录添加到Python路径
|
|
current_dir = Path(__file__).parent
|
|
src_dir = current_dir / "src"
|
|
sys.path.insert(0, str(src_dir))
|
|
|
|
from src.data.sentiment_fetcher import SentimentFetcher
|
|
|
|
|
|
def test_sentiment_features():
|
|
"""测试舆情功能"""
|
|
print("="*60)
|
|
print(" A股舆情数据功能测试")
|
|
print("="*60)
|
|
|
|
fetcher = SentimentFetcher()
|
|
|
|
# 1. 测试北向资金
|
|
print("\n🌊 1. 北向资金数据测试")
|
|
print("-" * 30)
|
|
current_flow = fetcher.get_north_flow_current()
|
|
if not current_flow.empty:
|
|
row = current_flow.iloc[0]
|
|
print(f"总净流入: {row.get('net_tgt', 'N/A')} 万元")
|
|
print(f"沪股通: {row.get('net_hgt', 'N/A')} 万元")
|
|
print(f"深股通: {row.get('net_sgt', 'N/A')} 万元")
|
|
print(f"更新时间: {row.get('trade_time', 'N/A')}")
|
|
else:
|
|
print("未获取到当前北向资金数据")
|
|
|
|
# 2. 测试热门股票
|
|
print("\n🔥 2. 热门股票数据测试")
|
|
print("-" * 30)
|
|
hot_stocks = fetcher.get_popular_stocks_east_100()
|
|
if not hot_stocks.empty:
|
|
print(f"东财人气股票TOP5:")
|
|
for idx, row in hot_stocks.head(5).iterrows():
|
|
code = row.get('stock_code', 'N/A')
|
|
name = row.get('short_name', 'N/A')
|
|
print(f" {idx + 1}. {code} - {name}")
|
|
else:
|
|
print("未获取到热门股票数据")
|
|
|
|
# 3. 测试龙虎榜
|
|
print("\n🐉 3. 龙虎榜数据测试")
|
|
print("-" * 30)
|
|
dragon_tiger = fetcher.get_dragon_tiger_list_daily()
|
|
if not dragon_tiger.empty:
|
|
print(f"今日龙虎榜 (共{len(dragon_tiger)}只股票):")
|
|
for idx, row in dragon_tiger.head(5).iterrows():
|
|
code = row.get('stock_code', 'N/A')
|
|
name = row.get('short_name', 'N/A')
|
|
reason = row.get('reason', 'N/A')
|
|
print(f" {idx + 1}. {code} - {name}")
|
|
print(f" 上榜原因: {reason}")
|
|
else:
|
|
print("今日无龙虎榜数据")
|
|
|
|
# 4. 测试热门概念
|
|
print("\n💡 4. 热门概念数据测试")
|
|
print("-" * 30)
|
|
try:
|
|
hot_concepts = fetcher.get_hot_concept_ths_20()
|
|
if not hot_concepts.empty:
|
|
print(f"同花顺热门概念TOP5:")
|
|
for idx, row in hot_concepts.head(5).iterrows():
|
|
name = row.get('concept_name', 'N/A')
|
|
change_pct = row.get('change_pct', 'N/A')
|
|
print(f" {idx + 1}. {name} (涨跌幅: {change_pct}%)")
|
|
else:
|
|
print("未获取到热门概念数据")
|
|
except Exception as e:
|
|
print(f"热门概念获取失败: {e}")
|
|
|
|
# 5. 测试市场舆情综合概览
|
|
print("\n📊 5. 市场舆情综合概览测试")
|
|
print("-" * 30)
|
|
try:
|
|
overview = fetcher.get_market_sentiment_overview()
|
|
if overview:
|
|
print("✅ 市场舆情概览获取成功")
|
|
|
|
# 北向资金
|
|
if 'north_flow' in overview:
|
|
north_data = overview['north_flow']
|
|
print(f"北向资金: 总净流入 {north_data.get('net_total', 'N/A')} 万元")
|
|
|
|
# 热门股票
|
|
if 'hot_stocks_east' in overview and not overview['hot_stocks_east'].empty:
|
|
count = len(overview['hot_stocks_east'])
|
|
print(f"热门股票: 获取到 {count} 只")
|
|
|
|
# 龙虎榜
|
|
if 'dragon_tiger' in overview and not overview['dragon_tiger'].empty:
|
|
count = len(overview['dragon_tiger'])
|
|
print(f"龙虎榜: 获取到 {count} 只")
|
|
else:
|
|
print("市场舆情概览获取失败")
|
|
except Exception as e:
|
|
print(f"市场舆情概览测试失败: {e}")
|
|
|
|
# 6. 测试个股舆情分析
|
|
print("\n🔍 6. 个股舆情分析测试")
|
|
print("-" * 30)
|
|
test_stock = "000001.SZ" # 平安银行
|
|
try:
|
|
analysis = fetcher.analyze_stock_sentiment(test_stock)
|
|
if 'error' not in analysis:
|
|
print(f"✅ {test_stock} 舆情分析成功")
|
|
print(f"东财人气榜: {'在榜' if analysis.get('in_popular_east', False) else '不在榜'}")
|
|
print(f"同花顺热门榜: {'在榜' if analysis.get('in_hot_ths', False) else '不在榜'}")
|
|
|
|
if 'dragon_tiger' in analysis and not analysis['dragon_tiger'].empty:
|
|
print("✅ 今日上榜龙虎榜")
|
|
else:
|
|
print("❌ 今日未上榜龙虎榜")
|
|
else:
|
|
print(f"个股舆情分析失败: {analysis.get('error', '未知错误')}")
|
|
except Exception as e:
|
|
print(f"个股舆情分析测试失败: {e}")
|
|
|
|
print("\n" + "="*60)
|
|
print(" 舆情数据功能测试完成")
|
|
print("="*60)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_sentiment_features() |