fix(orders): apply account-currency FX to the broker affordability gate#53
Merged
Merged
Conversation
When a strategy declares currency=currency.XXX differing from the symbol's quote currency (e.g. currency.INR on a USDT-quoted ETH perp), TradingView denominates equity in the account currency but the position notional in the quote currency, converting the latter via the account-currency FX rate before the required_margin <= equity affordability check. The engine assumed account == quote (FX 1.0), so it admitted entries TV's gate rejects -> over-fired ~2x on such scripts. Add account_currency_fx_ (default 1.0) plumbed through the existing syminfo_metadata channel (key "account_currency_fx" -> no new C-ABI export) and multiply required_margin by it in the strategy_entry affordability gate. Default 1.0 is a byte-identical no-op for every corpus strategy (none declare a foreign account currency). thulashimohanr-prev-day-week-levels-or-vwap (currency.INR, USD->INR FX~88): ~670 -> ~341 trades vs TV 330 (count blow-up collapses to ~excellent tier). Corpus held 251 excellent / 1 anomaly byte-identical; ctest 77/77 incl. new test_affordability_fx (reverting the FX factor makes test_fx_two_rejects fail). The scraped harness detects the currency= header and supplies the FX; corpus default 1.0 unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
When a strategy declares
currency=currency.XXXdiffering from the symbol's quote currency (e.g.currency.INRon a USDT-quoted ETH perp), TradingView denominates equity in the account currency but the position notional in the quote currency, converting the latter via the account-currency FX rate before therequired_margin <= equityaffordability check. The engine assumed account == quote (FX 1.0), so it admitted entries TV's gate rejects → over-fired ~2× on such scripts.Fix
Add
account_currency_fx_(default 1.0) plumbed through the existingsyminfo_metadatachannel (key"account_currency_fx"→ no new C-ABI export) and multiplyrequired_marginby it in thestrategy_entryaffordability gate. Default 1.0 is a byte-identical no-op for every corpus strategy.Validation
test_affordability_fx(reverting the FX factor →test_fx_two_rejectsfails)check_c_abi_runtime.pyThe companion scraped-harness change (detect the
currency=header, supply the FX) lands separately in the validation repo; the corpus default 1.0 is unaffected.🤖 Generated with Claude Code