feat: add portfolio ownership model, auth guards, and migration
This commit is contained in:
@@ -72,6 +72,7 @@ class Portfolio:
|
||||
status: str
|
||||
name: str
|
||||
symbol: str
|
||||
owner_user_id: str | None = None
|
||||
cash_balance: float = 0.0
|
||||
asset_quantity: float = 0.0
|
||||
price: float = 0.0
|
||||
|
||||
+11
-1
@@ -27,12 +27,14 @@ class PortfolioDomainRepository(Protocol):
|
||||
status: str = "enabled",
|
||||
active_strategy_id: str | None = None,
|
||||
avabile_strategies: list[str] | None = None,
|
||||
owner_user_id: str | None = None,
|
||||
initial_cash: float = 0.0,
|
||||
) -> Portfolio: ...
|
||||
def create_portfolio(
|
||||
self,
|
||||
portfolio_id: str,
|
||||
*,
|
||||
owner_user_id: str,
|
||||
broker: str,
|
||||
status: str,
|
||||
name: str,
|
||||
@@ -45,7 +47,13 @@ class PortfolioDomainRepository(Protocol):
|
||||
avabile_strategies: list[str] | None,
|
||||
) -> Portfolio: ...
|
||||
def update_portfolio(self, portfolio_id: str, **fields: object) -> Portfolio: ...
|
||||
def list_portfolios(self, *, broker: str | None = None, status: str | None = None) -> list[Portfolio]: ...
|
||||
def list_portfolios(
|
||||
self,
|
||||
*,
|
||||
broker: str | None = None,
|
||||
status: str | None = None,
|
||||
owner_user_id: str | None = None,
|
||||
) -> list[Portfolio]: ...
|
||||
def get_strategy_set(self, id: str) -> StrategySet | None: ...
|
||||
def get_or_create_strategy_set(self, name: str, config: str) -> StrategySet: ...
|
||||
def save(
|
||||
@@ -103,6 +111,7 @@ def apply_buy(
|
||||
status=portfolio.status,
|
||||
name=portfolio.name,
|
||||
symbol=portfolio.symbol,
|
||||
owner_user_id=portfolio.owner_user_id,
|
||||
cash_balance=float(portfolio.cash_balance) - total_cost,
|
||||
asset_quantity=float(portfolio.asset_quantity) + quantity,
|
||||
price=price,
|
||||
@@ -164,6 +173,7 @@ def apply_sell(
|
||||
status=portfolio.status,
|
||||
name=portfolio.name,
|
||||
symbol=portfolio.symbol,
|
||||
owner_user_id=portfolio.owner_user_id,
|
||||
cash_balance=float(portfolio.cash_balance) + net_proceeds,
|
||||
asset_quantity=float(portfolio.asset_quantity) - quantity,
|
||||
price=price,
|
||||
|
||||
Reference in New Issue
Block a user