- Generate runtime_id for service-token issuance (CLI and API)
- Implement GET /v1/assets endpoint with asset view and strategy_params
- Implement GET /v1/user_info endpoint with trading_enabled and broker credentials
- Implement POST /v1/assets/{asset_id}/ledger/trades with idempotency support
- Update auth service to support runtime_id tracking and credential encryption
- Add comprehensive test coverage for v1 endpoints (dcy-002 implementation)
- Update postgres repository for ledger and broker credential queries
- Ensure all tests pass for feature validation
166 lines
4.7 KiB
Python
166 lines
4.7 KiB
Python
"""Portfolio repository contract."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Protocol
|
|
|
|
from app.domain.models import AuthToken, LedgerEntry, Portfolio, PortfolioComment, PortfolioTag, StrategySet, TokenPrincipal, User
|
|
|
|
|
|
class PortfolioRepository(Protocol):
|
|
def ping(self) -> None: ...
|
|
|
|
def get_user(self, user_id: str) -> User: ...
|
|
|
|
def get_user_by_username(self, username: str) -> User | None: ...
|
|
|
|
def list_users(self) -> list[User]: ...
|
|
|
|
def create_user(
|
|
self,
|
|
username: str,
|
|
*,
|
|
email: str | None = None,
|
|
password_hash: str | None = None,
|
|
permission: str = "read",
|
|
is_active: bool = True,
|
|
) -> User: ...
|
|
|
|
def update_user(
|
|
self,
|
|
user_id: str,
|
|
*,
|
|
username: str | None = None,
|
|
email: str | None = None,
|
|
password_hash: str | None = None,
|
|
permission: str | None = None,
|
|
is_active: bool | None = None,
|
|
) -> User: ...
|
|
|
|
def delete_user(self, user_id: str) -> None: ...
|
|
|
|
def update_user_last_login(self, user_id: str) -> None: ...
|
|
|
|
def create_auth_token(
|
|
self,
|
|
user_id: str,
|
|
*,
|
|
name: str,
|
|
token_hash: str,
|
|
token_prefix: str,
|
|
permission: str,
|
|
token_type: str,
|
|
expires_at: datetime | None = None,
|
|
runtime_id: str | None = None,
|
|
) -> AuthToken: ...
|
|
|
|
def list_auth_tokens(self, user_id: str) -> list[AuthToken]: ...
|
|
|
|
def list_service_tokens(
|
|
self,
|
|
user_id: str | None = None,
|
|
*,
|
|
include_revoked: bool = False,
|
|
) -> list[AuthToken]: ...
|
|
|
|
def revoke_auth_token(self, user_id: str, token_id: str) -> None: ...
|
|
|
|
def get_service_token_by_name(self, name: str) -> AuthToken | None: ...
|
|
|
|
def get_token_principal(self, token_hash: str) -> TokenPrincipal | None: ...
|
|
|
|
def get(self, portfolio_id: str) -> Portfolio: ...
|
|
|
|
def get_or_create(
|
|
self,
|
|
portfolio_id: str,
|
|
symbol: str,
|
|
*,
|
|
name: str | None = None,
|
|
broker: str = "kis",
|
|
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,
|
|
symbol: str,
|
|
cash_balance: float,
|
|
asset_quantity: float,
|
|
asset_price: float,
|
|
profit_buffer: float,
|
|
active_strategy_id: str | None,
|
|
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,
|
|
owner_user_id: str | None = None,
|
|
include_tags: list[str] | None = None,
|
|
exclude_tags: list[str] | None = None,
|
|
match_mode: str | None = None,
|
|
) -> list[Portfolio]: ...
|
|
|
|
def add_tag(self, portfolio_id: str, *, tag: str) -> PortfolioTag: ...
|
|
|
|
def list_tags(self, portfolio_id: str) -> list[PortfolioTag]: ...
|
|
|
|
def remove_tag(self, portfolio_id: str, *, tag: str) -> None: ...
|
|
|
|
def get_or_create_strategy_set(self, name: str, config: str) -> StrategySet: ...
|
|
|
|
def get_strategy_set(self, id: str) -> StrategySet | None: ...
|
|
|
|
def list_strategy_sets(self) -> list[StrategySet]: ...
|
|
|
|
def delete_strategy_set(self, id: str) -> None: ...
|
|
|
|
def save(
|
|
self,
|
|
portfolio: Portfolio,
|
|
*,
|
|
current_price: float,
|
|
action: str,
|
|
trade_price: float,
|
|
quantity: float,
|
|
fee_amount: float,
|
|
tax_amount: float,
|
|
total_value_after: float,
|
|
strategy_set_id: str = "manual",
|
|
note: str = "",
|
|
) -> None: ...
|
|
|
|
def list_recent_trades(self, portfolio_id: str, limit: int = 5) -> list[LedgerEntry]: ...
|
|
|
|
def reset(self, portfolio_id: str) -> Portfolio: ...
|
|
|
|
def adjust_buffer(self, portfolio_id: str, amount: float, action: str, note: str = "") -> Portfolio: ...
|
|
|
|
def transfer_buffer(self, portfolio_id: str, amount: float, direction: str, note: str = "") -> Portfolio: ...
|
|
|
|
def delete(self, portfolio_id: str, *, clear_ledger: bool = True) -> None: ...
|
|
|
|
def create_comment(self, portfolio_id: str, *, content: str) -> PortfolioComment: ...
|
|
|
|
def list_comments(self, portfolio_id: str) -> list[PortfolioComment]: ...
|
|
|
|
def update_comment(self, portfolio_id: str, comment_id: str, *, content: str) -> PortfolioComment: ...
|
|
|
|
def delete_comment(self, portfolio_id: str, comment_id: str) -> None: ...
|
|
|