-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinal_intelligence_integration.py
More file actions
153 lines (122 loc) Β· 6.84 KB
/
Copy pathfinal_intelligence_integration.py
File metadata and controls
153 lines (122 loc) Β· 6.84 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
#!/usr/bin/env python3
"""
μ΅μ’
μ΅μ νλ Intelligence API ν΅ν© ν
μ€νΈ
"""
import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from data_monitoring.enhanced_data_collector import EnhancedGlobalDataCollector
import asyncio
import json
async def test_final_integration():
"""μ΅μ’
ν΅ν© ν
μ€νΈ"""
print("π μ΅μ’
μ΅μ νλ Intelligence API ν΅ν© ν
μ€νΈ")
print("=" * 60)
collector = EnhancedGlobalDataCollector()
# 1. Intelligence λ°μ΄ν° μμ§
print("\nπ§ Intelligence λ°μ΄ν° μμ§:")
print("-" * 40)
intelligence_data = collector.collect_intelligence_data()
if intelligence_data.get('status') == 'success':
print("β
Intelligence λ°μ΄ν° μμ§ μ±κ³΅!")
summary = intelligence_data.get('summary', {})
data = intelligence_data.get('data', {})
print(f"π μμ§ μμ½:")
print(f" π μμ₯ μν: {summary.get('market_status_count', 0)}κ°")
print(f" π μμΉ μ’
λͺ©: {summary.get('top_gainers_count', 0)}κ°")
print(f" π νλ½ μ’
λͺ©: {summary.get('top_losers_count', 0)}κ°")
print(f" π₯ νλ°ν κ±°λ: {summary.get('most_active_count', 0)}κ°")
print(f" π’ κ°μ₯ μμ₯: {summary.get('open_markets_count', 0)}κ°")
print(f" β οΈ μμ₯ λ³λμ±: {summary.get('market_volatility', 'unknown')}")
# νμ΄λΌμ΄νΈ νμ
if 'data' in intelligence_data:
intel_data = intelligence_data['data']
# κ°μ₯ μμ₯
market_status = intel_data.get('market_status', [])
if market_status:
open_markets = [m for m in market_status if m['current_status'] == 'open']
if open_markets:
print(f"\nπ’ νμ¬ κ°μ₯ μ€μΈ μμ₯:")
for market in open_markets[:5]:
print(f" β’ {market['region']}: {market['primary_exchanges']}")
# μμ μ’
λͺ©
top_movers = intel_data.get('top_gainers_losers', {})
if 'top_gainers' in top_movers and top_movers['top_gainers']:
print(f"\nπ μμ μμΉ μ’
λͺ©:")
for gainer in top_movers['top_gainers'][:3]:
print(f" π {gainer['ticker']}: +{gainer['change_percentage']} (κ±°λλ: {gainer['volume']:,})")
if 'top_losers' in top_movers and top_movers['top_losers']:
print(f"\nπ μμ νλ½ μ’
λͺ©:")
for loser in top_movers['top_losers'][:3]:
print(f" π {loser['ticker']}: {loser['change_percentage']} (κ±°λλ: {loser['volume']:,})")
if 'most_actively_traded' in top_movers and top_movers['most_actively_traded']:
print(f"\nπ₯ μ΅κ³ κ±°λλ μ’
λͺ©:")
for active in top_movers['most_actively_traded'][:3]:
print(f" π₯ {active['ticker']}: {active['change_percentage']} (κ±°λλ: {active['volume']:,})")
else:
print(f"β Intelligence λ°μ΄ν° μμ§ μ€ν¨: {intelligence_data.get('error', 'Unknown error')}")
# 2. μ’
ν© λ¦¬ν¬νΈ μμ±
print(f"\nπ μ’
ν© λ¦¬ν¬νΈ μμ±:")
print("-" * 40)
try:
comprehensive_report = await collector.generate_comprehensive_report_async()
print("β
μ’
ν© λ¦¬ν¬νΈ μμ± μ±κ³΅!")
print(f"π λ°μ΄ν° μμ€:")
data_sources = comprehensive_report.get('data_sources', {})
print(f" β’ Alpha Vantage νμ±ν: {data_sources.get('alphavantage_enabled', False)}")
print(f" β’ Intelligence νμ±ν: {data_sources.get('intelligence_enabled', False)}")
print(f" β’ λ΄μ€ μμ€: {data_sources.get('news_sources_count', 0)}κ°")
# κ°μ λΆμ
sentiment = comprehensive_report.get('sentiment_analysis', {})
if sentiment:
print(f" β’ μ 체 κ°μ μ μ: {sentiment.get('overall_sentiment', 0):.3f}")
distribution = sentiment.get('sentiment_distribution', {})
if distribution:
print(f" β’ κ°μ λΆν¬: κΈμ {distribution.get('positive', 0)}κ°, "
f"μ€λ¦½ {distribution.get('neutral', 0)}κ°, "
f"λΆμ {distribution.get('negative', 0)}κ°")
# Intelligence μΈμ¬μ΄νΈ
insights = comprehensive_report.get('intelligence_insights', {})
if insights:
print(f" β’ Intelligence μΈμ¬μ΄νΈ:")
if 'open_markets_count' in insights:
print(f" - κ°μ₯ μμ₯: {insights['open_markets_count']}κ°")
if 'top_gainer' in insights:
gainer = insights['top_gainer']
print(f" - μ΅κ³ μμΉ: {gainer['ticker']} ({gainer['change_percentage']}%)")
if 'top_loser' in insights:
loser = insights['top_loser']
print(f" - μ΅κ³ νλ½: {loser['ticker']} ({loser['change_percentage']}%)")
except Exception as e:
print(f"β μ’
ν© λ¦¬ν¬νΈ μμ± μ€ν¨: {e}")
# 3. κ²°κ³Ό μ μ₯
timestamp = intelligence_data.get('timestamp', '').replace(':', '').replace('-', '').replace('.', '')[:15]
output_file = f"output/final_intelligence_integration_{timestamp}.json"
final_result = {
'intelligence_data': intelligence_data,
'comprehensive_report': comprehensive_report if 'comprehensive_report' in locals() else {},
'test_summary': {
'intelligence_success': intelligence_data.get('status') == 'success',
'comprehensive_report_success': 'comprehensive_report' in locals(),
'total_market_status': summary.get('market_status_count', 0),
'total_top_movers': (
summary.get('top_gainers_count', 0) +
summary.get('top_losers_count', 0) +
summary.get('most_active_count', 0)
)
}
}
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(final_result, f, indent=2, ensure_ascii=False)
print(f"\n" + "=" * 60)
print("π― μ΅μ’
ν΅ν© ν
μ€νΈ μλ£!")
print(f"π κ²°κ³Ό μ μ₯: {output_file}")
# μ±κ³΅ μ¬λΆ μμ½
test_summary = final_result['test_summary']
print(f"\nπ ν
μ€νΈ κ²°κ³Ό:")
print(f" β
Intelligence API: {'μ±κ³΅' if test_summary['intelligence_success'] else 'μ€ν¨'}")
print(f" β
μ’
ν© λ¦¬ν¬νΈ: {'μ±κ³΅' if test_summary['comprehensive_report_success'] else 'μ€ν¨'}")
print(f" π μ΄ μμ§ λ°μ΄ν°: {test_summary['total_market_status'] + test_summary['total_top_movers']}κ°")
if __name__ == "__main__":
os.makedirs("output", exist_ok=True)
asyncio.run(test_final_integration())