BAT-004 (REQ-004, REQ-005):
- app/api/v1_tags.py: POST /v1/tags, GET /v1/tags, PATCH /v1/tags/{id}/deactivate
- app/api/v1_portfolios.py: POST/DELETE /v1/portfolios/{id}/tags
- app/api/v1_assets.py: POST/DELETE /v1/assets/{id}/tags 엔드포인트 추가
- app/schemas/v1.py: TagItem, TagCreateRequest, TagListResponse, TagApplyRequest/Response 추가
- app/repositories/portfolio_repository.py, postgres.py: append/remove_portfolio_tag_id 추가
- app/main.py: v1_portfolios_router, v1_tags_router 등록
- tests/test_tags_http_api.py: 22개 HTTP API 테스트
BAT-005 (REQ-007, REQ-008):
- app/cli/commands/tag.py: pfhub tag create/list/deactivate/apply/remove 7개 커맨드 신규
- app/cli/main.py: tag_app 등록
- app/cli/commands/portfolio.py: pfhub portfolio tag add/list/remove 완전 제거(breaking change)
- app/cli/core/utils.py: print_tag_table + list[Tag] render 분기 추가
- tests/test_tags_cli.py: REQ-007 AC-1~9 커버 24개 CLI 테스트 신규
- tests/test_cli.py: 제거된 portfolio tag 테스트 2개 삭제
- docs/data-model.md, interface-contract.md, project-structure.md, runtime-flows.md: 태그 모델 baseline 갱신(REQ-008)
- docs/batches/: BAT-004, BAT-005 전체 산출물(release-candidate)
247 passed
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
162 lines
4.4 KiB
Python
162 lines
4.4 KiB
Python
"""Schemas for v1 (Consumer-Driven Contract) API endpoints."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
from typing import Any, Literal
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# GET/POST/PATCH /v1/tags (REQ-004)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class TagItem(BaseModel):
|
|
tag_id: str
|
|
name: str
|
|
is_admin_tag: bool
|
|
is_active: bool
|
|
created_at: datetime | None = None
|
|
|
|
|
|
class TagCreateRequest(BaseModel):
|
|
name: str = Field(..., min_length=1)
|
|
|
|
|
|
class TagListResponse(BaseModel):
|
|
tags: list[TagItem]
|
|
total: int
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# POST/DELETE /v1/assets/{id}/tags, /v1/portfolios/{id}/tags (REQ-005)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class TagApplyRequest(BaseModel):
|
|
tag_id: str = Field(..., min_length=1)
|
|
|
|
|
|
class TagApplyResponse(BaseModel):
|
|
tag_id: str
|
|
status: str
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# GET /v1/assets
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class TagRefItem(BaseModel):
|
|
tag_id: str
|
|
archived: bool = False
|
|
|
|
|
|
class AssetItem(BaseModel):
|
|
asset_id: str
|
|
symbol: str
|
|
status: str
|
|
cash: float
|
|
quantity: float
|
|
broker_type: str
|
|
strategy_id: str | None = None
|
|
strategy_type: str | None = None
|
|
strategy_params: dict[str, Any] = {}
|
|
updated_at: datetime | None = None
|
|
# Additional informational fields
|
|
name: str | None = None
|
|
price: float | None = None
|
|
profit_buffer: float | None = None
|
|
tags: list[str] | None = None
|
|
tag_ids: list[TagRefItem] | None = None
|
|
owner_user_id: str | None = None
|
|
created_at: datetime | None = None
|
|
last_trade_at: datetime | None = None
|
|
|
|
|
|
class AssetsResponse(BaseModel):
|
|
assets: list[AssetItem]
|
|
total: int
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# GET /v1/user_info
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class BrokerItem(BaseModel):
|
|
broker: str
|
|
account_ref: str
|
|
credential_payload: dict[str, Any] | None = None
|
|
credential_version: int = 1
|
|
last_rotated_at: datetime | None = None
|
|
|
|
|
|
class UserInfoResponse(BaseModel):
|
|
runtime_id: str | None = None
|
|
daemon_id: str | None = None
|
|
trading_enabled: bool
|
|
disabled_reason: str | None = None
|
|
brokers: list[BrokerItem] = []
|
|
# Additional informational fields
|
|
user_id: str
|
|
username: str
|
|
email: str | None = None
|
|
permission: str
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# POST /v1/assets/{asset_id}/ledger/trades
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class LedgerTradeRequest(BaseModel):
|
|
order_id: str = Field(..., min_length=1)
|
|
execution_id: str = Field(..., min_length=1)
|
|
side: Literal["buy", "sell"]
|
|
quantity: Decimal = Field(..., gt=0)
|
|
price: Decimal = Field(..., gt=0)
|
|
fee_amount: Decimal = Field(default=Decimal("0"), ge=0)
|
|
tax_amount: Decimal = Field(default=Decimal("0"), ge=0)
|
|
executed_at: datetime
|
|
|
|
|
|
class LedgerTradeResponse(BaseModel):
|
|
ledger_entry_id: int
|
|
asset_id: str
|
|
order_id: str
|
|
execution_id: str
|
|
side: str
|
|
quantity: float
|
|
price: float
|
|
fee_amount: float
|
|
tax_amount: float
|
|
executed_at: datetime
|
|
recorded_at: datetime | None = None
|
|
status: Literal["new", "duplicate"] = "new"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# POST/PATCH /v1/assets (admin catalog management — REQ-010)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
class AssetCatalogCreateRequest(BaseModel):
|
|
symbol: str = Field(..., min_length=1)
|
|
markets: list[str] = Field(default_factory=list)
|
|
display_name: str | None = None
|
|
status: str = "active"
|
|
|
|
|
|
class AssetCatalogUpdateRequest(BaseModel):
|
|
markets: list[str] | None = None
|
|
display_name: str | None = None
|
|
status: str | None = None
|
|
|
|
|
|
class AssetCatalogResponse(BaseModel):
|
|
asset_id: str
|
|
symbol: str
|
|
markets: list[str]
|
|
display_name: str | None = None
|
|
status: str
|
|
created_at: datetime | None = None
|
|
updated_at: datetime | None = None
|