source: docs/P4-Prototype/UseCase0006Implementation.md@ b715712

main
Last change on this file since b715712 was b715712, checked in by Stefan <trsunovstefan@…>, 8 weeks ago

Add the server side and configuration

  • Property mode set to 100644
File size: 1.8 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(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 ```
223. **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 ![screenshot: portfolio view](screenshots/uc0006_portfolio.png)
29
30### Verified run
31
32With 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
481. **User** chooses `[7] View transaction history`.
492. **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 ![screenshot: transaction history](screenshots/uc0006_history.png)
Note: See TracBrowser for help on using the repository browser.