fix: 감사 잔여 항목 — 잔량 출처 DB화·ORB 영속화·미국 부분청산·듀얼전략 태깅·NULL 가격
- portfolio_cache_bridge: 잔량 산출을 Portfolio(DB) 기준으로. 캐시는 sync 실패 시 최대 5분 낡아 실제와 다른 잔량이 기록될 수 있었음(감사 #14). 조회 실패 시 캐시 폴백. - ORB 캐시 Redis 영속화(save/load_orb_cache) — 재배포 시 인메모리가 날아가 당일 ORB 전략이 통째로 불가능했음. 수집 후 저장, 스케줄러 기동·수집 시 복원. - us_market_scheduler: 부분청산이 Portfolio.quantity 를 갱신하지 않던 문제 → reflect_sell 연동. - 듀얼 전략(MOMENTUM_BREAKOUT/PULLBACK_BUY)이 ActiveTrade.strategy_name 에 저장되지 않아 CLAUDE.md §8.4 모멘텀 전용 청산(+10%/+20% 분할)이 한 번도 실행된 적 없었음 → 태깅 전달. 매도 시에는 실제 행의 strategy_name 으로 close (swing 으로 닫으면 유령 행 잔존). - 수동매도: current_price NULL 시 TypeError 로 주문 후 상태 갱신이 통째로 누락되던 엣지 수정. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1493,9 +1493,13 @@ async def sell_stock(
|
||||
raise HTTPException(status_code=500, detail=f"매도 주문 실패: {error_msg}")
|
||||
|
||||
# TradeHistory 기록
|
||||
executed_price = price if price else holding.current_price # 체결가는 나중에 업데이트
|
||||
profit_loss = (executed_price - holding.average_price) * quantity
|
||||
profit_loss_rate = ((executed_price / holding.average_price) - 1) * 100
|
||||
# 체결가는 나중에 업데이트. current_price 가 NULL 이면 평균단가로 폴백 —
|
||||
# None 연산으로 TypeError 가 나면 주문은 이미 나간 뒤라 상태 갱신이 전부 누락된다.
|
||||
_exec_raw = price or holding.current_price or holding.average_price or 0
|
||||
executed_price = Decimal(str(_exec_raw))
|
||||
_avg_dec = Decimal(str(original_avg_price)) if original_avg_price > 0 else None
|
||||
profit_loss = float((executed_price - _avg_dec) * quantity) if _avg_dec else 0.0
|
||||
profit_loss_rate = float((executed_price / _avg_dec - 1) * 100) if _avg_dec else 0.0
|
||||
|
||||
# CLAUDE.md 3.2: db_worker 큐 경유
|
||||
from app.services.db_worker import enqueue_trade_history
|
||||
|
||||
Reference in New Issue
Block a user