fix corporate action runtime blockers

This commit is contained in:
2026-09-13 14:22:41 +09:00
parent 925c6b4fa4
commit fa824dfd36
4 changed files with 70 additions and 4 deletions
+2 -1
View File
@@ -24,6 +24,7 @@ from app.core.auth import AuthContext, Permission, require_read, require_trade_w
from app.core.config import get_settings
from app.domain.errors import DaemonInactiveError, DaemonNotFoundError
from app.domain.models import CorporateAction, Portfolio, PortfolioComment
from app.domain.services import PORTFOLIO_NOT_FOUND_MESSAGE
from app.domain.pnl import calculate_current_wac, calculate_realized_pnl
from app.repositories.factory import get_portfolio_repository_from_settings
from app.schemas.v1 import (
@@ -1332,7 +1333,7 @@ def create_corporate_action(portfolio_id: str, payload: CorporateActionRequest,
return CorporateActionResponse(**saved.__dict__)
except ValueError as exc:
code = str(exc)
if code == "portfolio not found":
if code == PORTFOLIO_NOT_FOUND_MESSAGE:
raise HTTPException(status_code=404, detail="Portfolio not found") from exc
raise HTTPException(status_code=409 if code.startswith(("IDEMPOTENCY", "CORPORATE_ACTION_")) else 400, detail=code) from exc
finally:
+2 -2
View File
@@ -7,7 +7,7 @@ from typing import Callable, Protocol
from app.domain.models import LedgerEntry, LiveAssetSource, Portfolio, StrategySet
_NOT_FOUND_MSG = "포트폴리오를 찾을 수 없습니다"
PORTFOLIO_NOT_FOUND_MESSAGE = "포트폴리오를 찾을 수 없습니다"
_INVEST_ACTION_MAP = {
"deposit": "INVEST",
"profit": "PROFIT",
@@ -250,7 +250,7 @@ def apply_reset(
portfolio = repo.reset(portfolio_id)
return portfolio, False
except ValueError as exc:
if str(exc) != _NOT_FOUND_MSG:
if str(exc) != PORTFOLIO_NOT_FOUND_MESSAGE:
raise
symbol = infer_symbol(portfolio_id)
portfolio = repo.get_or_create(portfolio_id, symbol, initial_cash=0.0)
+1 -1
View File
@@ -1654,7 +1654,7 @@ class PostgresPortfolioRepository:
return action
if row[4] != "enabled":
raise ValueError("CORPORATE_ACTION_PORTFOLIO_DISABLED")
if row[3] != action.asset_id:
if str(row[3]) != str(action.asset_id):
raise ValueError("CORPORATE_ACTION_ASSET_MISMATCH")
if Decimal(str(row[1])) != action.cash_balance or Decimal(str(row[2])) != action.profit_buffer:
raise ValueError("CORPORATE_ACTION_INVARIANT_MISMATCH")