schemas.holding_schemas¶
src.schemas.holding_schemas
¶
Holding request and response schemas.
Pydantic schemas for holding API endpoints. Includes: - Request schemas (client → API) - Response schemas (API → client) - DTO-to-schema conversion methods
Reference
- docs/architecture/api-design-patterns.md
Classes¶
HoldingResponse
¶
Bases: BaseModel
Single holding response.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Holding unique identifier. |
account_id |
UUID
|
Account FK. |
provider_holding_id |
str
|
Provider's unique ID for position. |
symbol |
str
|
Security ticker symbol. |
security_name |
str
|
Full security name. |
asset_type |
str
|
Asset type (equity, etf, option, etc.). |
quantity |
Decimal
|
Number of shares/units. |
cost_basis |
Decimal
|
Total cost paid. |
market_value |
Decimal
|
Current market value. |
currency |
str
|
ISO 4217 currency code. |
average_price |
Decimal | None
|
Average cost per share. |
current_price |
Decimal | None
|
Current market price per share. |
unrealized_gain_loss |
Decimal | None
|
Computed gain/loss. |
unrealized_gain_loss_percent |
Decimal | None
|
Computed gain/loss percentage. |
is_active |
bool
|
Whether position is active. |
is_profitable |
bool
|
Whether position is profitable. |
last_synced_at |
datetime | None
|
Last sync timestamp. |
created_at |
datetime
|
Creation timestamp. |
updated_at |
datetime
|
Last update timestamp. |
Source code in src/schemas/holding_schemas.py
Functions¶
from_dto
classmethod
¶
Convert application DTO to response schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dto
|
HoldingResult
|
HoldingResult from handler. |
required |
Returns:
| Type | Description |
|---|---|
HoldingResponse
|
HoldingResponse for API response. |
Source code in src/schemas/holding_schemas.py
HoldingListResponse
¶
Bases: BaseModel
Holding list response with aggregates.
Attributes:
| Name | Type | Description |
|---|---|---|
holdings |
list[HoldingResponse]
|
List of holdings. |
total_count |
int
|
Total number of holdings. |
active_count |
int
|
Number of active holdings. |
total_market_value_by_currency |
dict[str, str]
|
Aggregated market values. |
total_cost_basis_by_currency |
dict[str, str]
|
Aggregated cost basis. |
total_unrealized_gain_loss_by_currency |
dict[str, str]
|
Aggregated gain/loss. |
Source code in src/schemas/holding_schemas.py
Functions¶
from_dto
classmethod
¶
Convert application DTO to response schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dto
|
HoldingListResult
|
HoldingListResult from handler. |
required |
Returns:
| Type | Description |
|---|---|
HoldingListResponse
|
HoldingListResponse for API response. |
Source code in src/schemas/holding_schemas.py
SyncHoldingsResponse
¶
Bases: SyncResponse
Response for holdings sync operation.
Extends SyncResponse with holdings-specific fields.
Attributes:
| Name | Type | Description |
|---|---|---|
holdings_created |
int
|
Number of new holdings created. |
holdings_updated |
int
|
Number of existing holdings updated. |
holdings_deactivated |
int
|
Number of holdings deactivated. |
Source code in src/schemas/holding_schemas.py
SyncHoldingsRequest
¶
Bases: BaseModel
Request to sync holdings from provider.
Attributes:
| Name | Type | Description |
|---|---|---|
force |
bool
|
Force sync even if recently synced. |