feat: add rebalancing API endpoints
This commit is contained in:
parent
a45c44740e
commit
5f3c6061c9
@ -14,7 +14,9 @@ from app.schemas.portfolio import (
|
||||
TargetCreate, TargetResponse,
|
||||
HoldingCreate, HoldingResponse,
|
||||
TransactionCreate, TransactionResponse,
|
||||
RebalanceResponse, RebalanceSimulationRequest, RebalanceSimulationResponse,
|
||||
)
|
||||
from app.services.rebalance import RebalanceService
|
||||
|
||||
router = APIRouter(prefix="/api/portfolios", tags=["portfolios"])
|
||||
|
||||
@ -289,3 +291,28 @@ async def add_transaction(
|
||||
db.commit()
|
||||
db.refresh(transaction)
|
||||
return transaction
|
||||
|
||||
|
||||
@router.get("/{portfolio_id}/rebalance", response_model=RebalanceResponse)
|
||||
async def calculate_rebalance(
|
||||
portfolio_id: int,
|
||||
current_user: CurrentUser,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Calculate rebalancing for a portfolio."""
|
||||
portfolio = _get_portfolio(db, portfolio_id, current_user.id)
|
||||
service = RebalanceService(db)
|
||||
return service.calculate_rebalance(portfolio)
|
||||
|
||||
|
||||
@router.post("/{portfolio_id}/rebalance/simulate", response_model=RebalanceSimulationResponse)
|
||||
async def simulate_rebalance(
|
||||
portfolio_id: int,
|
||||
data: RebalanceSimulationRequest,
|
||||
current_user: CurrentUser,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Simulate rebalancing with additional investment amount."""
|
||||
portfolio = _get_portfolio(db, portfolio_id, current_user.id)
|
||||
service = RebalanceService(db)
|
||||
return service.calculate_rebalance(portfolio, additional_amount=data.additional_amount)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user