From 628b431171cfae441123de5fd9c5f8719b5e8ea9 Mon Sep 17 00:00:00 2001 From: ayuriel Date: Mon, 16 Feb 2026 12:50:21 +0900 Subject: [PATCH] feat: include stock names in snapshot, transaction, and backtest transaction API responses --- backend/app/api/backtest.py | 7 +++++++ backend/app/api/portfolio.py | 20 +++++++++++++++++++- backend/app/api/snapshot.py | 12 ++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/backend/app/api/backtest.py b/backend/app/api/backtest.py index e636370..218ccfa 100644 --- a/backend/app/api/backtest.py +++ b/backend/app/api/backtest.py @@ -17,6 +17,7 @@ from app.schemas.backtest import ( EquityCurvePoint, RebalanceHoldings, HoldingItem, TransactionItem, ) from app.services.backtest import submit_backtest +from app.services.rebalance import RebalanceService router = APIRouter(prefix="/api/backtest", tags=["backtest"]) @@ -228,11 +229,17 @@ async def get_transactions( .all() ) + # Resolve stock names + tickers = list({t.ticker for t in transactions}) + name_service = RebalanceService(db) + names = name_service.get_stock_names(tickers) + return [ TransactionItem( id=t.id, date=t.date, ticker=t.ticker, + name=names.get(t.ticker), action=t.action, shares=t.shares, price=t.price, diff --git a/backend/app/api/portfolio.py b/backend/app/api/portfolio.py index 4d92ad0..ad6882d 100644 --- a/backend/app/api/portfolio.py +++ b/backend/app/api/portfolio.py @@ -231,7 +231,25 @@ async def get_transactions( .limit(limit) .all() ) - return transactions + + # Resolve stock names + tickers = list({tx.ticker for tx in transactions}) + service = RebalanceService(db) + names = service.get_stock_names(tickers) + + return [ + TransactionResponse( + id=tx.id, + ticker=tx.ticker, + name=names.get(tx.ticker), + tx_type=tx.tx_type.value, + quantity=tx.quantity, + price=tx.price, + executed_at=tx.executed_at, + memo=tx.memo, + ) + for tx in transactions + ] @router.post("/{portfolio_id}/transactions", response_model=TransactionResponse, status_code=status.HTTP_201_CREATED) diff --git a/backend/app/api/snapshot.py b/backend/app/api/snapshot.py index a9d57b3..b3ac29f 100644 --- a/backend/app/api/snapshot.py +++ b/backend/app/api/snapshot.py @@ -16,6 +16,7 @@ from app.schemas.portfolio import ( ReturnsResponse, ReturnDataPoint, ) from app.services.price_service import PriceService +from app.services.rebalance import RebalanceService router = APIRouter(prefix="/api/portfolios", tags=["snapshots"]) @@ -110,6 +111,10 @@ async def create_snapshot( db.commit() db.refresh(snapshot) + # Get stock names + name_service = RebalanceService(db) + names = name_service.get_stock_names(tickers) + return SnapshotResponse( id=snapshot.id, portfolio_id=snapshot.portfolio_id, @@ -118,6 +123,7 @@ async def create_snapshot( holdings=[ SnapshotHoldingResponse( ticker=h.ticker, + name=names.get(h.ticker), quantity=h.quantity, price=h.price, value=h.value, @@ -150,6 +156,11 @@ async def get_snapshot( if not snapshot: raise HTTPException(status_code=404, detail="Snapshot not found") + # Get stock names + tickers = [h.ticker for h in snapshot.holdings] + name_service = RebalanceService(db) + names = name_service.get_stock_names(tickers) + return SnapshotResponse( id=snapshot.id, portfolio_id=snapshot.portfolio_id, @@ -158,6 +169,7 @@ async def get_snapshot( holdings=[ SnapshotHoldingResponse( ticker=h.ticker, + name=names.get(h.ticker), quantity=h.quantity, price=h.price, value=h.value,