fix: ActiveTrade 잔량 자동 정합 + PATCH 수량 교정 지원
수동/분할 매도 누락으로 ActiveTrade 잔량이 실제 보유량과 어긋나면 다음 청산이
보유량보다 많이 매도한다. 동기화 시 종목당 active 행이 1개뿐일 때 실제 보유량으로
교정하고, 보유가 없으면 closed 처리(스윙+DT 혼재 종목은 자동 교정 제외).
운영 교정용으로 PATCH /portfolio/active-trades/{code}/status 에 quantity 필드 추가.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -136,3 +136,21 @@ def test_manual_sell_closes_active_trade():
|
||||
src = inspect.getsource(pf.sell_stock)
|
||||
assert "_enq_close_at(stock_code" in src
|
||||
assert '"quantity": original_holding_qty - quantity' in src
|
||||
|
||||
|
||||
def test_sync_reconciles_active_trade_quantity():
|
||||
"""동기화가 ActiveTrade 잔량을 실제 보유량으로 정합해야 드리프트가 누적되지 않는다."""
|
||||
import inspect
|
||||
from app.api.endpoints import portfolio as pf
|
||||
src = inspect.getsource(pf.sync_portfolio)
|
||||
assert "ActiveTrade 잔량 교정" in src
|
||||
assert "len(_rows) != 1" in src, "스윙+DT 혼재 종목은 자동 교정 대상에서 제외해야 함"
|
||||
assert "_row.status = \"closed\"" in src, "보유 없음 → closed 처리 누락"
|
||||
|
||||
|
||||
def test_active_trade_patch_supports_quantity():
|
||||
import inspect
|
||||
from app.api.endpoints import portfolio as pf
|
||||
assert "quantity" in pf.ActiveTradeStatusUpdateRequest.model_fields
|
||||
src = inspect.getsource(pf.update_active_trade_status)
|
||||
assert "active_trade.quantity = request.quantity" in src
|
||||
|
||||
Reference in New Issue
Block a user