fix: 분할매도 잔량 미갱신 — 스윙·국내 executor·미국 경로 동일 패턴 + 수동매도 ActiveTrade 정리
DT에서 찾은 '분할매도 후 ActiveTrade.quantity 미갱신' 패턴이 3곳 더 있었음: - us_market_scheduler: total_qty = trade.quantity 를 매도량 산정에 직접 사용 → 분할매도 후 다음 사이클이 원래 수량 기준으로 팔아 과다매도(US_TRADING_ENABLED=true 상태) - swing/exit_service, trade_executor._execute_sell: remaining_pct만 갱신 또한 수동 매도(/portfolio/sell)가 ActiveTrade를 전혀 정리하지 않아 청산된 종목이 active로 잔존(삼아알미늄·LG 등) → 재매수 시 옛 remaining_pct가 살아나 1차 익절이 건너뛰어짐. 전량 매도 시 close, 분할 시 잔량 갱신으로 수정. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -349,6 +349,9 @@ async def check_and_execute_exit_v2(db: AsyncSession) -> list[dict]:
|
||||
_at_data = {
|
||||
"stock_code": stock_code,
|
||||
"remaining_pct": new_remaining,
|
||||
# 잔량도 함께 갱신 — 누락 시 재기동 복원이 원래 수량으로 되살아나
|
||||
# 보유량보다 많이 매도한다(2026-09-23 DT LG씨엔에스 사례와 동일 패턴)
|
||||
"quantity": quantity - sell_qty,
|
||||
"highest_since_entry": latest_price if latest_price > (trailing_high or 0) else trailing_high,
|
||||
}
|
||||
if active_trade is None:
|
||||
|
||||
Reference in New Issue
Block a user