타입에러 수정
This commit is contained in:
@@ -124,9 +124,11 @@ async def batch_analysis_scheduler():
|
|||||||
"recommendations:latest", TTL_RECOMMENDATIONS, normalized
|
"recommendations:latest", TTL_RECOMMENDATIONS, normalized
|
||||||
)
|
)
|
||||||
if ok:
|
if ok:
|
||||||
|
rec_by_rule = normalized.get('recommendations_by_rule', [])
|
||||||
|
rec_count = len(rec_by_rule) if isinstance(rec_by_rule, (list, dict)) else 0
|
||||||
logger.info(
|
logger.info(
|
||||||
f"💾 [Batch] Redis 캐시 갱신 완료: recommendations:latest "
|
f"💾 [Batch] Redis 캐시 갱신 완료: recommendations:latest "
|
||||||
f"(rule 수: {len(normalized.get('recommendations_by_rule', {}))}, "
|
f"(rule 수: {rec_count}, "
|
||||||
f"TTL: {TTL_RECOMMENDATIONS}s)"
|
f"TTL: {TTL_RECOMMENDATIONS}s)"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -191,9 +193,11 @@ async def auto_trade_scheduler():
|
|||||||
# ── Redis 캐시 확인 (10분 배치 결과, TTL 30분) ────────────────
|
# ── Redis 캐시 확인 (10분 배치 결과, TTL 30분) ────────────────
|
||||||
rec = await get_json("recommendations:latest")
|
rec = await get_json("recommendations:latest")
|
||||||
if rec:
|
if rec:
|
||||||
|
rec_by_rule = rec.get('recommendations_by_rule', [])
|
||||||
|
rec_count = len(rec_by_rule) if isinstance(rec_by_rule, (list, dict)) else 0
|
||||||
logger.info(
|
logger.info(
|
||||||
"⚡ Redis cache hit: recommendations:latest "
|
"⚡ Redis cache hit: recommendations:latest "
|
||||||
f"(rule 수: {len(rec.get('recommendations_by_rule', {}))}) "
|
f"(rule 수: {rec_count}) "
|
||||||
"→ DB 조회 생략"
|
"→ DB 조회 생략"
|
||||||
)
|
)
|
||||||
# 포맷 정규화 (다른 키 조합 대응)
|
# 포맷 정규화 (다른 키 조합 대응)
|
||||||
@@ -205,15 +209,14 @@ async def auto_trade_scheduler():
|
|||||||
|
|
||||||
if rec and rec.get("recommendations_by_rule"):
|
if rec and rec.get("recommendations_by_rule"):
|
||||||
# ── MCP RISK_ASSESSMENT (공통 함수, 이슈 4) ──────────
|
# ── MCP RISK_ASSESSMENT (공통 함수, 이슈 4) ──────────
|
||||||
recommendations = rec.get("recommendations_by_rule", {})
|
recommendations = rec.get("recommendations_by_rule", [])
|
||||||
trade_plan = {
|
|
||||||
"action": "BUY",
|
# Handle both list and dict formats for backwards compatibility
|
||||||
"strategy": "rule_based_batch",
|
if isinstance(recommendations, dict):
|
||||||
"recommendation_count": sum(
|
# Old format: {rule_name: [stocks]}
|
||||||
len(v) for v in recommendations.values()
|
recommendation_count = sum(len(v) for v in recommendations.values())
|
||||||
),
|
rules_list = list(recommendations.keys())
|
||||||
"rules": list(recommendations.keys()),
|
top_stocks_list = [
|
||||||
"top_stocks": [
|
|
||||||
item.get("stock_code") or item.get("code", "")
|
item.get("stock_code") or item.get("code", "")
|
||||||
for rule_items in recommendations.values()
|
for rule_items in recommendations.values()
|
||||||
for item in (
|
for item in (
|
||||||
@@ -221,12 +224,37 @@ async def auto_trade_scheduler():
|
|||||||
if isinstance(rule_items, list)
|
if isinstance(rule_items, list)
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
][:10],
|
][:10]
|
||||||
|
else:
|
||||||
|
# New format: [{rule_id, rule_name, stocks: [...]}]
|
||||||
|
recommendation_count = sum(
|
||||||
|
len(rule_group.get("stocks", []))
|
||||||
|
for rule_group in recommendations
|
||||||
|
if isinstance(rule_group, dict)
|
||||||
|
)
|
||||||
|
rules_list = [
|
||||||
|
rule_group.get("rule_name", rule_group.get("rule_id", ""))
|
||||||
|
for rule_group in recommendations
|
||||||
|
if isinstance(rule_group, dict)
|
||||||
|
]
|
||||||
|
top_stocks_list = [
|
||||||
|
item.get("stock_code") or item.get("code", "")
|
||||||
|
for rule_group in recommendations
|
||||||
|
if isinstance(rule_group, dict)
|
||||||
|
for item in rule_group.get("stocks", [])[:3]
|
||||||
|
][:10]
|
||||||
|
|
||||||
|
trade_plan = {
|
||||||
|
"action": "BUY",
|
||||||
|
"strategy": "rule_based_batch",
|
||||||
|
"recommendation_count": recommendation_count,
|
||||||
|
"rules": rules_list,
|
||||||
|
"top_stocks": top_stocks_list,
|
||||||
}
|
}
|
||||||
portfolio: dict = {}
|
portfolio: dict = {}
|
||||||
signals = {
|
signals = {
|
||||||
"source": "db_recommendations",
|
"source": "db_recommendations",
|
||||||
"rules_triggered": list(recommendations.keys()),
|
"rules_triggered": rules_list,
|
||||||
}
|
}
|
||||||
approve, reason = await request_mcp_risk_assessment(
|
approve, reason = await request_mcp_risk_assessment(
|
||||||
trade_plan, portfolio, signals
|
trade_plan, portfolio, signals
|
||||||
|
|||||||
Reference in New Issue
Block a user