Changeset ef1c1c7 for docs/P3-UseCaseModel
- Timestamp:
- 09/24/26 17:43:19 (5 days ago)
- Branches:
- main
- Children:
- 0cee8ec
- Parents:
- a531b45
- Location:
- docs/P3-UseCaseModel
- Files:
-
- 9 added
- 3 edited
-
UseCase0004.md (modified) (3 diffs)
-
UseCase0005.md (modified) (1 diff)
-
UseCase0007.md (modified) (2 diffs)
-
wiki/UseCase0001.md (added)
-
wiki/UseCase0002.md (added)
-
wiki/UseCase0003.md (added)
-
wiki/UseCase0004.md (added)
-
wiki/UseCase0005.md (added)
-
wiki/UseCase0006.md (added)
-
wiki/UseCase0007.md (added)
-
wiki/UseCaseModel.md (added)
-
wiki/UseCaseModelAIUsage.md (added)
Legend:
- Unmodified
- Added
- Removed
-
docs/P3-UseCaseModel/UseCase0004.md
ra531b45 ref1c1c7 10 10 11 11 1. Trader chooses "Place market BUY order". 12 2. System lists the a vailable marketswith their latest price:12 2. System lists the active markets, numbered, with their latest price: 13 13 14 14 ```sql 15 SELECT m.id, c.symbol, m.quote_currency, COALESCE(lp.price, 0) 15 SELECT m.id, c.id, c.symbol, m.quote_currency, 16 COALESCE(lp.price, 0) AS price 16 17 FROM project.markets m 17 18 JOIN project.crypto c ON c.id = m.crypto_id … … 20 21 ORDER BY c.symbol; 21 22 ``` 22 3. Trader enters a market symbol, e.g. `ETH`. 23 4. System resolves the market and looks up the latest price: 23 3. Trader picks the market by its number in the listed markets, e.g. `2` (BTC). 24 4. System takes the chosen row's market id and crypto id from the list (no lookup by 25 symbol) and looks up the latest price: 24 26 25 27 ```sql 26 SELECT m.id, c.id AS crypto_id, c.symbol, m.quote_currency 27 FROM project.markets m 28 JOIN project.crypto c ON c.id = m.crypto_id 29 WHERE upper(c.symbol) = upper($1) AND m.is_active = true; 30 31 SELECT price FROM project.v_latest_prices WHERE market_id = $2; 28 SELECT price FROM project.v_latest_prices WHERE market_id = $1; 32 29 ``` 33 30 5. Trader enters a quantity. … … 91 88 If `available_balance < notional`, the entire transaction rolls back and system shows "Insufficient funds: need X, have Y." 92 89 93 ### Alternate flow 4a — market not found90 ### Alternate flow 3a — number not in the list 94 91 95 If the entered symbol does not match any active market, system shows "market X not found" and returns to the authenticated menu without opening a transaction.92 If the entered number is not one of the listed market numbers, system shows "Invalid choice, enter a number from 1 to N." and returns to the authenticated menu without opening a transaction. -
docs/P3-UseCaseModel/UseCase0005.md
ra531b45 ref1c1c7 26 26 27 27 1. Trader chooses "Place market SELL order". 28 2. System lists markets (same SQL as UC0004 step 2). 29 3. Trader enters market symbol and quantity. 30 4. System resolves the market and looks up the latest price (same SQL as UC0004 step 4). 28 2. System lists, numbered, the Trader's holdings that still have a quantity free to 29 sell (not reserved by an open sell order), with the quantity held, the free 30 quantity and the latest price: 31 32 ```sql 33 SELECT m.id, c.id, c.symbol, m.quote_currency, 34 h.quantity, h.quantity - h.reserved_quantity AS free, 35 COALESCE(lp.price, 0) AS price 36 FROM project.holdings h 37 JOIN project.crypto c ON c.id = h.crypto_id 38 JOIN project.markets m ON m.crypto_id = c.id AND m.is_active = true 39 LEFT JOIN project.v_latest_prices lp ON lp.market_id = m.id 40 WHERE h.user_id = $1 41 AND h.quantity - h.reserved_quantity > 0 42 ORDER BY c.symbol; 43 ``` 44 3. Trader picks the holding by its number in the listed holdings, e.g. `2` (ETH), and 45 enters the quantity. 46 4. System takes the chosen row's market id and crypto id from the list (no lookup by 47 symbol) and looks up the latest price: 48 49 ```sql 50 SELECT price FROM project.v_latest_prices WHERE market_id = $1; 51 ``` 31 52 5. System opens a transaction: 32 53 -
docs/P3-UseCaseModel/UseCase0007.md
ra531b45 ref1c1c7 40 40 ### Add a crypto 41 41 42 The Trader picks the crypto by its number from the listed cryptos that are not on the watchlist yet: 43 42 44 ```sql 43 -- 1. resolve the symbol to a crypto_id 44 SELECT id FROM project.crypto WHERE upper(symbol) = upper($1); 45 -- 1. list, numbered, the cryptos not yet on the watchlist 46 SELECT c.id, c.symbol, c.name 47 FROM project.crypto c 48 WHERE NOT EXISTS (SELECT 1 FROM project.watchlist_items wi 49 WHERE wi.watchlist_id = $1 AND wi.crypto_id = c.id) 50 ORDER BY c.symbol; 45 51 46 -- 2. insert the item; do nothing if it's already there52 -- 2. insert the chosen crypto ($2 = its id from the list); do nothing if it's already there 47 53 INSERT INTO project.watchlist_items (watchlist_id, crypto_id) 48 VALUES ($ watchlist_id, $crypto_id)54 VALUES ($1, $2) 49 55 ON CONFLICT (watchlist_id, crypto_id) DO NOTHING; 50 56 ``` … … 52 58 ### Remove a crypto 53 59 60 The Trader picks the crypto by its number from the listed cryptos on the watchlist: 61 54 62 ```sql 63 -- 1. list, numbered, the cryptos on the watchlist 64 SELECT c.id, c.symbol, c.name 65 FROM project.watchlist_items wi 66 JOIN project.crypto c ON c.id = wi.crypto_id 67 WHERE wi.watchlist_id = $1 68 ORDER BY c.symbol; 69 70 -- 2. delete the chosen crypto ($2 = its id from the list) 55 71 DELETE FROM project.watchlist_items 56 WHERE watchlist_id = $1 57 AND crypto_id = ( 58 SELECT id FROM project.crypto 59 WHERE upper(symbol) = upper($2) 60 ); 72 WHERE watchlist_id = $1 AND crypto_id = $2; 61 73 ``` 62 74 63 If the delete affects zero rows, system shows "Not in watchlist."75 If the entered number is not one of the listed numbers, system shows "Invalid choice, enter a number from 1 to N." and nothing is changed.
Note:
See TracChangeset
for help on using the changeset viewer.
