feat: 자동매매 신뢰성 개선 — 시세 실서버 라우팅·일일 한도 전역화·수동 매수 API
- korea_investment_api: KIS_QUOTES_VIA_REAL — 모의투자 모드에서 시세/차트/호가 조회를 실계좌 시세 서버(20/s)로 위임, 주문·잔고는 모의서버 유지 (EGW00201 대응) - recommendations: execute_auto_trade_background asyncio.Lock 중복 실행 방지 + MAX_DAILY_TRADES를 당일 BUY 건수 차감 전역 기준으로 적용 (11종목 동시 매수 재발 방지) - manual_buy.py 신규: POST /api/v1/portfolio/buy (리스크 가드 + safe_place_order + db_worker) - mcp-server: claude_code_client(claude -p 헤드리스 모드) 추가, trade_monitor 부분매도 시 active 유지·remaining_pct 갱신, API 키 헤더·/api/v1 경로 수정, ODNO 주문ID 수정 - config: MCP_REQUEST_TIMEOUT, MCP_RISK_CACHE_TTL, BATCH_ANALYSIS_INTERVAL, SWING_INDEX_BREAKER_ENABLED(OFF), API_TRIGGERED_AUTO_TRADE(OFF) 추가 - docker-compose: 포트 충돌 해소 (postgres 15433, frontend 3001) - frontend: 추천 패널 매수 버튼, 차트/호가/저널 패널 개선 - CLAUDE.md 압축 최적화 (규칙 변경 없음), _sweep_single_axis.py 백테스트 단일축 스윕 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -462,12 +462,14 @@ async def db_writer_worker() -> None:
|
||||
else:
|
||||
# remaining_pct_multiply: 기존 remaining_pct에 비율을 곱함
|
||||
# (MDD 축소 시 기존 분할매도 이력 반영)
|
||||
multiply_ratio = data.pop("remaining_pct_multiply", None)
|
||||
# data.get() 사용 — pop()으로 task dict를 파괴적으로 변경하면
|
||||
# 재시도 시 이 키가 사라져 no-op으로 성공 처리되는 버그 방지
|
||||
multiply_ratio = data.get("remaining_pct_multiply")
|
||||
if multiply_ratio is not None:
|
||||
current_remaining = getattr(record, "remaining_pct", 1.0) or 1.0
|
||||
record.remaining_pct = current_remaining * float(multiply_ratio)
|
||||
record.remaining_pct = float(current_remaining) * float(multiply_ratio)
|
||||
for key, val in data.items():
|
||||
if key != "stock_code" and val is not None:
|
||||
if key not in ("stock_code", "remaining_pct_multiply") and val is not None:
|
||||
setattr(record, key, val)
|
||||
|
||||
await session.commit()
|
||||
@@ -525,6 +527,10 @@ async def db_writer_worker() -> None:
|
||||
while not queue.empty():
|
||||
try:
|
||||
drain_task = queue.get_nowait()
|
||||
except asyncio.QueueEmpty:
|
||||
# get_nowait()이 실패해 아이템을 꺼내지 못했으므로 task_done() 호출 금지
|
||||
break
|
||||
try:
|
||||
drain_type = drain_task.get("type", "unknown")
|
||||
drain_data = drain_task.get("data")
|
||||
async with AsyncSessionLocal() as drain_session:
|
||||
@@ -548,8 +554,6 @@ async def db_writer_worker() -> None:
|
||||
else:
|
||||
await _save_to_dlq(drain_task, "shutdown_drain_unknown_type")
|
||||
remaining += 1
|
||||
except asyncio.QueueEmpty:
|
||||
break
|
||||
except Exception as drain_err:
|
||||
logger.error(f"[DBWorker] Drain 실패: {drain_err}")
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user