source: docs/P4-Prototype/UseCase0006Implementation.md@ 9577c79

main
Last change on this file since 9577c79 was 9577c79, checked in by Stefan <trsunovstefan@…>, 13 days ago

add reserved_quantity and modify the phases, add v_03.png and v_03.xml for P1

  • Property mode set to 100644
File size: 2.3 KB
Line 
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
91. **User** chooses `[6] View portfolio`.
102. **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 ```
243. **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 ![screenshot: portfolio view](screenshots/uc0006_portfolio.png)
31
32### Verified run
33
34Re-run 2026-09-16 against PostgreSQL 16 with the seed data (`data_load.sql`).
35Immediately 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
52snapshot taken with crypto actually reserved.
53
54### Transaction history
55
561. **User** chooses `[7] View transaction history`.
572. **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 ![screenshot: transaction history](screenshots/uc0006_history.png)
Note: See TracBrowser for help on using the repository browser.