fix(trading): include fees in cash risk checks - #4
Open
ECD5A wants to merge 1 commit into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ExchangeClientcontractReceipt
Before this change, a portfolio with
$100.00cash could buy0.001 BTC @ $100,000with a 10 bps fee. The risk check compared only the$100.00notional to cash and allowed the order; the fill then debited$100.10, leaving cash at-$0.10.The two new regression tests reproduced that failure before the implementation change: the direct risk decision was
allowed: true, and the engine outcome wasfilled. Both now block the order before it reaches the exchange.Design alignment
This advances Conviction 5: the deterministic pre-trade guard is the last line of defense. It also protects the cash/NAV accounting invariant described in ADR 0005.
Tests
npm run buildnode --test --test-reporter=spec --test-name-pattern=RiskEngine|TradingEngine|MockExchange|LiveExchange test/local.mjs— 14 passedgit diff --checkA full local
npm testrun reaches the relevant trading suite successfully but has unrelated existing failures in Windows HOME/temp-directory isolation tests.