Ignore:
Timestamp:
09/24/26 17:43:19 (5 days ago)
Author:
Stefan <trsunovstefan@…>
Branches:
main
Children:
0cee8ec
Parents:
a531b45
Message:

Wiki docs, phase 6 and phase 7 added

Location:
docs/P3-UseCaseModel
Files:
9 added
3 edited

Legend:

Unmodified
Added
Removed
  • docs/P3-UseCaseModel/UseCase0004.md

    ra531b45 ref1c1c7  
    1010
    11111. Trader chooses "Place market BUY order".
    12 2. System lists the available markets with their latest price:
     122. System lists the active markets, numbered, with their latest price:
    1313
    1414   ```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
    1617     FROM project.markets m
    1718     JOIN project.crypto  c  ON c.id = m.crypto_id
    … …  
    2021    ORDER BY c.symbol;
    2122   ```
    22 3. Trader enters a market symbol, e.g. `ETH`.
    23 4. System resolves the market and looks up the latest price:
     233. Trader picks the market by its number in the listed markets, e.g. `2` (BTC).
     244. 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:
    2426
    2527   ```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;
    3229   ```
    33305. Trader enters a quantity.
    … …  
    9188If `available_balance < notional`, the entire transaction rolls back and system shows "Insufficient funds: need X, have Y."
    9289
    93 ### Alternate flow 4a — market not found
     90### Alternate flow 3a — number not in the list
    9491
    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.
     92If 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  
    2626
    27271. 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).
     282. 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   ```
     443. Trader picks the holding by its number in the listed holdings, e.g. `2` (ETH), and
     45   enters the quantity.
     464. 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   ```
    31525. System opens a transaction:
    3253
  • docs/P3-UseCaseModel/UseCase0007.md

    ra531b45 ref1c1c7  
    4040### Add a crypto
    4141
     42The Trader picks the crypto by its number from the listed cryptos that are not on the watchlist yet:
     43
    4244```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
     46SELECT 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;
    4551
    46 -- 2. insert the item; do nothing if it's already there
     52-- 2. insert the chosen crypto ($2 = its id from the list); do nothing if it's already there
    4753INSERT INTO project.watchlist_items (watchlist_id, crypto_id)
    48 VALUES ($watchlist_id, $crypto_id)
     54VALUES ($1, $2)
    4955ON CONFLICT (watchlist_id, crypto_id) DO NOTHING;
    5056```
    … …  
    5258### Remove a crypto
    5359
     60The Trader picks the crypto by its number from the listed cryptos on the watchlist:
     61
    5462```sql
     63-- 1. list, numbered, the cryptos on the watchlist
     64SELECT 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)
    5571DELETE 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;
    6173```
    6274
    63 If the delete affects zero rows, system shows "Not in watchlist."
     75If 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.