챠트 데이터 웹소켓으로 연결

This commit is contained in:
2026-02-26 13:51:12 +09:00
parent 82346fcc46
commit 77e7464884
4 changed files with 82 additions and 5 deletions

View File

@@ -98,8 +98,20 @@ async def execute_auto_trade_background(recommendations_response: dict, db: Asyn
result = await db.execute(select(Portfolio).where(Portfolio.quantity > 0))
held_stocks = {p.stock_code for p in result.scalars().all()}
# normalize recommendations_by_rule early so we iterate over a list of groups
rec_groups = recommendations_response.get("recommendations_by_rule", [])
if isinstance(rec_groups, dict):
# older format: {rule_name: [stocks]}
normalized_list = []
for name, group in rec_groups.items():
if isinstance(group, dict):
normalized_list.append(group)
else:
normalized_list.append({"rule_name": name, "stocks": group})
rec_groups = normalized_list
unique_stocks = {}
for rule_group in recommendations_response.get("recommendations_by_rule", []):
for rule_group in rec_groups:
# make sure we have a dict with expected keys
if not isinstance(rule_group, dict):
logger.warning("Invalid rule_group in recommendations_response: %r", rule_group)