Changeset ef1c1c7 for docs/P1-ConceptualModel
- Timestamp:
- 09/24/26 17:43:19 (6 days ago)
- Branches:
- main
- Children:
- 0cee8ec
- Parents:
- a531b45
- Location:
- docs/P1-ConceptualModel
- Files:
-
- 4 added
- 2 edited
-
ERModel.md (modified) (7 diffs)
-
ERModelAIUsage.md (modified) (1 diff)
-
ERModel_v04.png (added)
-
ERModel_v04.xml (added)
-
wiki/ERModel.md (added)
-
wiki/ERModelAIUsage.md (added)
Legend:
- Unmodified
- Added
- Removed
-
docs/P1-ConceptualModel/ERModel.md
ra531b45 ref1c1c7 1 # Entity-Relationship Model v.0 31 # Entity-Relationship Model v.04 2 2 3 3 ## Diagram 4 4 5 5  6 6 7 7 Notation: Chen. Rectangles are entity sets, diamonds are relationships, ellipses … … 51 51 | `available_balance` | numeric(18,4) | required, default 0, ≥ 0 | 52 52 | `invested_balance` | numeric(18,4) | required, default 0, ≥ 0 | 53 | `reserved_balance` | numeric(18,4) | required, default 0, ≥ 0 — cash set aside for the user's open buy orders (added in v04, after P7) | 53 54 | `created_at` | timestamptz | required, defaults to now | 54 55 | `updated_at` | timestamptz | optional (null until first change) | … … 96 97 makes the ledger auditable. 97 98 98 Placing an order is what triggers a **reservation** of whatever it commits — 99 the crypto being sold (`Holds.reserved_quantity`, below) on a sell, cash 100 already handled the same way on a buy via `available_balance` / 101 `invested_balance`. `status` therefore has real meaning as a lifecycle, not 102 just a label: `open` means reserved but not yet settled, `executed` means 103 settled, `cancelled` would release the reservation without settling (not yet 104 exercised by any use case, since only market orders — which settle 105 immediately — are implemented). See 99 Placing an order is what triggers a **reservation** of whatever it commits: 100 the crypto being sold (`Holds.reserved_quantity`, below) on a sell, and the 101 cash (`Users.reserved_balance`) on a buy. Since v04 (after P7) an order can 102 wait in the order book and be filled in parts, so `status` is a real 103 lifecycle driven by `filled_quantity`: `open` (nothing filled yet), 104 `partially_filled`, `executed` (completely filled), or `cancelled`, which 105 releases what is still reserved. See 106 106 [UseCase0005](../P3-UseCaseModel/UseCase0005.md) for the reserve-then-settle 107 sequence. 107 sequence and 108 [AdvancedDatabaseDevelopment](../P7-AdvancedDatabaseDevelopment/AdvancedDatabaseDevelopment.md) 109 for the rules that keep it consistent. 108 110 109 111 **Keys:** candidate `{id}` only — there is no natural key, since the same user … … 115 117 | `id` | UUID | PK, required | 116 118 | `side` | text | required, `buy` or `sell` | 117 | `type` | text | required, `market` or `limit` — the prototype executes only `market`; `limit` exists so the model does not have to change when limit orders are implemented|118 | `status` | text | required, `open`, ` executed` or `cancelled` |119 | `type` | text | required, `market` or `limit` (both executed since P7) | 120 | `status` | text | required, `open`, `partially_filled`, `executed` or `cancelled` | 119 121 | `quantity` | numeric(20,4) | required, > 0 | 120 | `price` | numeric(18,6) | optional — null until the order settles, then the fill price | 122 | `filled_quantity` | numeric(20,4) | required, default 0, between 0 and `quantity` — how much has been traded; remaining = `quantity − filled_quantity` (added in v04, after P7) | 123 | `price` | numeric(18,6) | the limit price; for a market order, the market price when it was placed | 121 124 | `placed_at` | timestamptz | required, defaults to now | 122 125 | `executed_at` | timestamptz | optional, set when the order settles | … … 160 163 | `source` | text(50) | required, default `simulation` — distinguishes a simulated trade from a user's own fill (`user`) | 161 164 165 Since v04 (after P7) a trade also records which orders it filled, through the 166 relationships `FillsBuy` and `FillsSell` below. 167 168 #### OrderEvents 169 *Added in v04, after P7.* The audit trail of an order: one event for its 170 placement, one for every (partial) fill, and one for a cancellation. The 171 `Orders` row only holds the current state; this entity keeps the history of 172 how the order got there. Events are recorded automatically by the database. 173 174 **Keys:** candidate `{id}` only; primary key **`id`** (auto-incrementing 175 integer, events are only read in order). 176 177 | Attribute | Type | Constraints | 178 |---|---|---| 179 | `id` | integer | PK, required, auto-generated | 180 | `event_type` | text | required, `placed`, `partially_filled`, `filled` or `cancelled` | 181 | `quantity` | numeric(20,4) | required — the ordered quantity for `placed`, the filled amount for a fill, the unfilled rest for `cancelled` | 182 | `price` | numeric(18,6) | optional — the order price, or the trade price for a fill | 183 | `status_after` | text | required, the order's status after the event | 184 | `created_at` | timestamptz | required, defaults to now | 185 162 186 #### MarketCandles 163 187 OHLCV aggregates per market and timeframe — the data a price chart is drawn … … 222 246 #### Fills — Markets (1) : MarketTrades (N), total on MarketTrades 223 247 Every executed trade happened on exactly one market. No attributes. 248 249 #### FillsBuy — Orders (1) : MarketTrades (N), partial on both sides 250 *Added in v04, after P7.* The buy order a trade filled. An order can be 251 filled by many trades (partial fills); a trade fills at most one buy order, 252 and none when the simulated market was the buyer. No attributes. 253 254 #### FillsSell — Orders (1) : MarketTrades (N), partial on both sides 255 *Added in v04, after P7.* The sell order a trade filled, symmetric to 256 `FillsBuy`. A trade between two users' orders participates in both. No 257 attributes. 258 259 #### Logs — Orders (1) : OrderEvents (N), total on OrderEvents 260 *Added in v04, after P7.* Every event belongs to exactly one order. No 261 attributes. 224 262 225 263 #### Aggregates — Markets (1) : MarketCandles (N), total on MarketCandles … … 290 328 [UseCase0005](../P3-UseCaseModel/UseCase0005.md) for how the new attribute 291 329 is enforced. 330 - **v04 — after P7.** Phase 7 (order, balance and trade consistency) needed 331 data the model did not have, so the model was extended to stay in line with 332 the database: 333 - `Users.reserved_balance`: cash reserved by open buy orders; 334 - `Orders.filled_quantity` and the status value `partially_filled`: orders 335 can now be filled in parts; 336 - the relationships `FillsBuy` and `FillsSell` between `Orders` and 337 `MarketTrades`: which orders a trade filled; 338 - the entity set `OrderEvents` with the relationship `Logs`: the 339 automatically recorded history of every order. 340 341 Nothing existing was removed or changed. See 342 [AdvancedDatabaseDevelopment](../P7-AdvancedDatabaseDevelopment/AdvancedDatabaseDevelopment.md). 343 The diagram files are `ERModel_v04.xml` / `ERModel_v04.png`; earlier versions 344 are kept. 292 345 293 346 Reasoning for the AI-assisted part of this phase, and the full interaction log, 294 347 are on [ERModelAIUsage](ERModelAIUsage.md). 295 348 296 > **Student action required.** Open `ERModel_v03.xml` in TerraER, read the297 > whole diagram — not just the new `reserved_quantity` ellipse — and change298 > anything you disagree with, including the compaction. The phase rules299 > require the model to be yours; this is a generated revision to review and300 > take over, not an answer to submit unread. -
docs/P1-ConceptualModel/ERModelAIUsage.md
ra531b45 ref1c1c7 283 283 white `(255,255,255)`, matching `ERModel_v02.png`. 284 284 285 > **Student action required.** Open `ERModel_v03.xml` in TerraER and read it 286 > end to end before submission — see the note at the end of 287 > [ERModel](ERModel.md). Everything else in this session's diff is already 288 > applied to the docs and to `server/`. 285 286 ### Session 4 — 2026-09-24 (Claude Opus 5.5): v04 after P7 287 288 **Prompts (student, verbatim):** 289 > But this order_events is added after Phase 7 right? can we add that too? 290 291 > can you make the ERmodel again with TerraER file to update it? and tell that after P7 we added this 292 293 > Make it with a white background like earier versions 294 295 **Response (AI, summarised):** 296 297 - Explained that the P7 changes must also appear in P1 and P2, since both must describe the 298 current data structure. 299 - Built `ERModel_v04.xml` in TerraER's own file format by taking `ERModel_v03.xml` unchanged 300 and appending the new elements with the same XML structure TerraER uses: 301 - the attribute `reserved_balance` on `Users`; 302 - the attribute `filled_quantity` on `Orders`; 303 - the relationships `FillsBuy` and `FillsSell` (Orders 1 : N MarketTrades, partial); 304 - the entity set `OrderEvents` (key `id`, `event_type`, `quantity`, `price`, 305 `status_after`, `created_at`) with `Logs` (Orders 1 : N OrderEvents, total on 306 OrderEvents). 307 - Rendered `ERModel_v04.png` with TerraER 3.14's own drawing classes (loading the `.xml` 308 exactly as TerraER does and using its image export), on a white background and trimmed like 309 the earlier versions. 310 - Updated [ERModel](ERModel.md) (title v.04, new attribute rows, the `OrderEvents` section, the 311 three relationships, and a v04 history entry stating these were added after P7). 312 313 **What I decided:** to add the P7 structure to the ER model. The new elements are placed 314 automatically, so the layout can be tidied by hand in TerraER.
Note:
See TracChangeset
for help on using the changeset viewer.
