Skip to content

fix(orders): apply account-currency FX to the broker affordability gate#53

Merged
luisleo526 merged 1 commit into
mainfrom
fix/account-currency-fx-affordability
Jun 30, 2026
Merged

fix(orders): apply account-currency FX to the broker affordability gate#53
luisleo526 merged 1 commit into
mainfrom
fix/account-currency-fx-affordability

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Problem

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 ~2× on such scripts.

Fix

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.

Validation

result
thulashimohanr (currency.INR, USD→INR FX≈88) ~670 → ~341 trades vs TV 330 (count blow-up → ~excellent tier)
corpus 251 excellent / 1 anomaly / 0 fail (byte-identical; default FX 1.0)
ctest 77/77 incl. new test_affordability_fx (reverting the FX factor → test_fx_two_rejects fails)
check_c_abi_runtime.py exit 0

The 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

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>
@luisleo526 luisleo526 merged commit 78b5300 into main Jun 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant