application.queries.handlers.get_holding_handler¶
src.application.queries.handlers.get_holding_handler
¶
GetHolding query handler.
Handles requests to retrieve a single holding. Returns DTO (not domain entity) to prevent leaking domain to presentation.
Architecture: - Application layer handler (orchestrates data retrieval) - Returns Result[DTO, str] (explicit error handling) - NO domain events (queries are side-effect free) - Ownership verification: Holding->Account->ProviderConnection->User
Reference
- docs/architecture/cqrs.md
Classes¶
HoldingDetailResult
dataclass
¶
Single holding result DTO.
Represents a holding for API response. Money value objects converted to separate amount+currency fields for serialization.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
UUID
|
Holding unique identifier. |
account_id |
UUID
|
Account FK. |
provider_holding_id |
str
|
Provider's unique ID. |
symbol |
str
|
Security ticker symbol. |
security_name |
str
|
Full security name. |
asset_type |
str
|
Asset type as string (e.g., "equity", "option"). |
quantity |
Decimal
|
Number of shares/units. |
cost_basis |
Decimal
|
Total cost basis amount. |
cost_basis_currency |
str
|
Cost basis currency code. |
market_value |
Decimal
|
Current market value amount. |
market_value_currency |
str
|
Market value currency code. |
average_price |
Decimal | None
|
Average cost per share or None. |
average_price_currency |
str | None
|
Average price currency or None. |
current_price |
Decimal | None
|
Current market price per share or None. |
current_price_currency |
str | None
|
Current price currency or None. |
unrealized_gain_loss |
Decimal
|
Unrealized gain/loss amount. |
unrealized_gain_loss_currency |
str
|
Unrealized gain/loss currency. |
unrealized_gain_loss_percent |
Decimal | None
|
Gain/loss percentage or None. |
is_active |
bool
|
Whether position is active. |
is_profitable |
bool
|
Whether position is profitable. |
last_synced_at |
datetime | None
|
Last provider sync timestamp or None. |
created_at |
datetime
|
First sync timestamp. |
updated_at |
datetime
|
Last update timestamp. |
Source code in src/application/queries/handlers/get_holding_handler.py
GetHoldingError
¶
GetHolding-specific errors.
Source code in src/application/queries/handlers/get_holding_handler.py
GetHoldingHandler
¶
Handler for GetHolding query.
Retrieves a single holding by ID with ownership verification. Uses OwnershipVerifier to verify: Holding->Account->ProviderConnection->User
Dependencies (injected via constructor): - OwnershipVerifier: For holding retrieval with ownership verification
Source code in src/application/queries/handlers/get_holding_handler.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
Functions¶
__init__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ownership_verifier
|
OwnershipVerifier
|
Service for ownership verification. |
required |
Source code in src/application/queries/handlers/get_holding_handler.py
handle
async
¶
Handle GetHolding query.
Retrieves holding, verifies ownership via Account->Connection chain, and maps to DTO.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
GetHolding
|
GetHolding query with holding and user IDs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Success |
HoldingDetailResult
|
Holding found and owned by user. |
Failure |
error
|
Holding not found or not owned by user. |