-
Notifications
You must be signed in to change notification settings - Fork 2
fix(rails): exempt DCA buys from the total-exposure rail; rail 14 bounds DCA (#841) #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Rail 4 — the total open-exposure cap | ||
|
|
||
| Rail 4 is one of keel's hard rails: checks in `keel/execution/guards.py` that run before every | ||
| order, in every mode, and cannot be switched off or widened from outside that module. This one | ||
| caps the **summed open notional** across every asset — everything bought and not yet sold, from | ||
| the orders audit log — plus the order being placed, at `caps.max_exposure_usd` in config.yaml. | ||
|
|
||
| It is a **notional** cap, not an at-risk cap: $5k behind a 2% stop and $5k behind a 20% stop | ||
| count the same (KB §83.3). | ||
|
|
||
| ## Who it binds: rule-trading BUYs, not DCA | ||
|
|
||
| Since #841 (the operator's decision, 2026-09-27), **DCA BUYs are exempt from this rail**: | ||
|
|
||
| > DCA is bounded by the venue plan's cap (rail 14, the attested monthly buy cap), not by | ||
| > `caps.max_exposure_usd`. | ||
|
|
||
| A fixed total-holdings cap stops a multi-rule accumulation sleeve within weeks whatever the plan | ||
| is: with 7 DCA rules, about $213 held against a $400 cap left room for about one more buy. | ||
|
|
||
| What the exemption does and does not change: | ||
|
|
||
| | Rail | Rule-trading BUY | DCA BUY | | ||
| |---|---|---| | ||
| | 4 — total open exposure (`total_exposure_cap`) | binds | **exempt** (#841) | | ||
| | 6 — per-asset concentration (`per_asset_concentration_cap`) | binds | binds | | ||
| | 14 — monthly buy cap (`monthly_subscription_allowance`) | binds | binds — the limit that bounds DCA | | ||
| | 8 — no averaging into losers | binds | exempt (§8/§12.1) | | ||
| | 11 — account-drawdown breaker | binds | exempt (§12.6) | | ||
| | 16 — consecutive-loss breaker | binds | exempt (§12.6) | | ||
| | every other rail | binds | binds | | ||
|
|
||
| Two consequences worth knowing: | ||
|
|
||
| - **DCA holdings still count toward the total.** A rule-trading entry sees the whole book, | ||
| DCA lots included, so a growing DCA sleeve shrinks the room rule trades have under | ||
| `max_exposure_usd`. | ||
| - **Rail 6 still uses `max_exposure_usd`.** The per-asset limit is | ||
| `max_per_asset_pct × max_exposure_usd`, so `max_exposure_usd` still bounds DCA per asset, | ||
| just not in total. | ||
|
|
||
| `keel simulate` applies the same exemption (`SimAccount.can_open`), so a backtest models what | ||
| live does. | ||
|
|
||
| ## What happens when it is exceeded | ||
|
|
||
| A rule-trading BUY is **vetoed** before it reaches the venue: | ||
|
|
||
| - `total_exposure_cap: open exposure … + … = … exceeds max_exposure_usd …` | ||
|
|
||
| SELLs are never checked by this rail — they reduce exposure. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.