| 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(avg_price, 0),
|
|---|
| 15 | COALESCE(current_price, 0),
|
|---|
| 16 | COALESCE(market_value, 0),
|
|---|
| 17 | COALESCE(unrealized_pnl, 0)
|
|---|
| 18 | FROM v_portfolio
|
|---|
| 19 | WHERE user_id = $1 AND quantity > 0
|
|---|
| 20 | ORDER BY symbol;
|
|---|
| 21 | ```
|
|---|
| 22 | 3. **System** renders a table with a totals row, then prints the cash summary:
|
|---|
| 23 |
|
|---|
| 24 | ```sql
|
|---|
| 25 | SELECT available_balance, invested_balance FROM users WHERE id = $1;
|
|---|
| 26 | ```
|
|---|
| 27 |
|
|---|
| 28 | 
|
|---|
| 29 |
|
|---|
| 30 | ### Verified run
|
|---|
| 31 |
|
|---|
| 32 | With the seed data (`data_load.sql`), immediately after login, alice's portfolio prints:
|
|---|
| 33 |
|
|---|
| 34 | ```
|
|---|
| 35 | Symbol Quantity Avg buy Current Value Unrealised P/L
|
|---|
| 36 | ------------------------------------------------------------------------------------
|
|---|
| 37 | ETH 0.5000 3500.000000 3520.000000 1760.0000 +10.0000
|
|---|
| 38 | ------------------------------------------------------------------------------------
|
|---|
| 39 | TOTAL 1760.0000 +10.0000
|
|---|
| 40 |
|
|---|
| 41 | Cash available : 8250.0000 USD
|
|---|
| 42 | Portfolio value: 1760.0000 USD
|
|---|
| 43 | Net worth : 10010.0000 USD
|
|---|
| 44 | ```
|
|---|
| 45 |
|
|---|
| 46 | ### Transaction history
|
|---|
| 47 |
|
|---|
| 48 | 1. **User** chooses `[7] View transaction history`.
|
|---|
| 49 | 2. **System** runs:
|
|---|
| 50 |
|
|---|
| 51 | ```sql
|
|---|
| 52 | SELECT created_at, type, amount, currency, COALESCE(description, '')
|
|---|
| 53 | FROM transactions
|
|---|
| 54 | WHERE user_id = $1
|
|---|
| 55 | ORDER BY created_at DESC
|
|---|
| 56 | LIMIT 20;
|
|---|
| 57 | ```
|
|---|
| 58 |
|
|---|
| 59 | 
|
|---|