| 1 | # Use-case 0006 Implementation — Portfolio & transactions
|
|---|
| 2 |
|
|---|
| 3 | **Initiating actor:** Trader. **Source files:** `server/portfolio.go` (`ShowPortfolio`), `server/account.go` (`ShowTransactions`, `ShowBalance`).
|
|---|
| 4 |
|
|---|
| 5 | ## Scenario (implemented)
|
|---|
| 6 |
|
|---|
| 7 | ### Portfolio
|
|---|
| 8 |
|
|---|
| 9 | 1. **User** chooses `[6] View portfolio`.
|
|---|
| 10 | 2. **System** runs:
|
|---|
| 11 |
|
|---|
| 12 | ```sql
|
|---|
| 13 | SELECT symbol, quantity,
|
|---|
| 14 | COALESCE(reserved_quantity, 0),
|
|---|
| 15 | COALESCE(available_quantity, quantity),
|
|---|
| 16 | COALESCE(avg_price, 0),
|
|---|
| 17 | COALESCE(current_price, 0),
|
|---|
| 18 | COALESCE(market_value, 0),
|
|---|
| 19 | COALESCE(unrealized_pnl, 0)
|
|---|
| 20 | FROM v_portfolio
|
|---|
| 21 | WHERE user_id = $1 AND quantity > 0
|
|---|
| 22 | ORDER BY symbol;
|
|---|
| 23 | ```
|
|---|
| 24 | 3. **System** renders a table with a totals row, then prints the cash summary:
|
|---|
| 25 |
|
|---|
| 26 | ```sql
|
|---|
| 27 | SELECT available_balance, invested_balance FROM users WHERE id = $1;
|
|---|
| 28 | ```
|
|---|
| 29 |
|
|---|
| 30 | 
|
|---|
| 31 |
|
|---|
| 32 | ### Verified run
|
|---|
| 33 |
|
|---|
| 34 | Re-run 2026-09-16 against PostgreSQL 16 with the seed data (`data_load.sql`).
|
|---|
| 35 | Immediately after login, alice's portfolio prints (now with the
|
|---|
| 36 | `Reserved`/`Available` columns from `holdings.reserved_quantity`):
|
|---|
| 37 |
|
|---|
| 38 | ```
|
|---|
| 39 | Symbol Quantity Reserved Available Avg buy Current Value Unrealised P/L
|
|---|
| 40 | ------------------------------------------------------------------------------------------------------------------
|
|---|
| 41 | ETH 0.5000 0.0000 0.5000 3500.000000 3520.000000 1760.0000 +10.0000
|
|---|
| 42 | ------------------------------------------------------------------------------------------------------------------
|
|---|
| 43 | TOTAL 1760.0000 +10.0000
|
|---|
| 44 |
|
|---|
| 45 | Cash available : 8250.0000 USD
|
|---|
| 46 | Portfolio value: 1760.0000 USD
|
|---|
| 47 | Net worth : 10010.0000 USD
|
|---|
| 48 | ```
|
|---|
| 49 |
|
|---|
| 50 | `Reserved` is 0.0000 here because nothing is mid-sell; see
|
|---|
| 51 | [UseCase0005Implementation](UseCase0005Implementation.md) for a portfolio
|
|---|
| 52 | snapshot taken with crypto actually reserved.
|
|---|
| 53 |
|
|---|
| 54 | ### Transaction history
|
|---|
| 55 |
|
|---|
| 56 | 1. **User** chooses `[7] View transaction history`.
|
|---|
| 57 | 2. **System** runs:
|
|---|
| 58 |
|
|---|
| 59 | ```sql
|
|---|
| 60 | SELECT created_at, type, amount, currency, COALESCE(description, '')
|
|---|
| 61 | FROM transactions
|
|---|
| 62 | WHERE user_id = $1
|
|---|
| 63 | ORDER BY created_at DESC
|
|---|
| 64 | LIMIT 20;
|
|---|
| 65 | ```
|
|---|
| 66 |
|
|---|
| 67 | 
|
|---|