챠트 데이터 웹소켓으로 연결
This commit is contained in:
@@ -605,11 +605,22 @@ async def execute_auto_trading(db: AsyncSession = Depends(get_db)):
|
||||
total_processed = 0
|
||||
max_trades = 5
|
||||
|
||||
for rule_group in recommendations_response["recommendations_by_rule"]:
|
||||
# make sure we iterate a list of rule group dicts
|
||||
rec_groups = recommendations_response.get("recommendations_by_rule", [])
|
||||
if isinstance(rec_groups, dict):
|
||||
normalized = []
|
||||
for name, grp in rec_groups.items():
|
||||
if isinstance(grp, dict):
|
||||
normalized.append(grp)
|
||||
else:
|
||||
normalized.append({"rule_name": name, "stocks": grp})
|
||||
rec_groups = normalized
|
||||
|
||||
for rule_group in rec_groups:
|
||||
if total_processed >= max_trades:
|
||||
break
|
||||
|
||||
for stock in rule_group["stocks"][:settings.AUTO_TRADE_TOP_N_PER_RULE]:
|
||||
for stock in rule_group.get("stocks", [])[:settings.AUTO_TRADE_TOP_N_PER_RULE]:
|
||||
if total_processed >= max_trades:
|
||||
break
|
||||
|
||||
|
||||
@@ -128,7 +128,8 @@ class MarketData(Base):
|
||||
stock_code = Column(String(20), nullable=False, index=True)
|
||||
price = Column(Numeric(15, 2), nullable=False)
|
||||
change_rate = Column(Numeric(10, 4))
|
||||
volume = Column(Integer)
|
||||
# real‑time volume may also exceed int32; switch to bigint for safety
|
||||
volume = Column(BigInteger)
|
||||
high_price = Column(Numeric(15, 2))
|
||||
low_price = Column(Numeric(15, 2))
|
||||
open_price = Column(Numeric(15, 2))
|
||||
@@ -190,7 +191,8 @@ class StockAnalysis(Base):
|
||||
# 가격 정보
|
||||
current_price = Column(Integer, nullable=False)
|
||||
change_rate = Column(Numeric(10, 4))
|
||||
volume = Column(Integer)
|
||||
# volumes can exceed 32‑bit limits (e.g. 3 billion+), use bigint to avoid overflow
|
||||
volume = Column(BigInteger)
|
||||
|
||||
# 기술적 지표
|
||||
rsi = Column(Numeric(10, 4))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user