Skip to content

Fix symbol detection in waitForChartReady (~8x faster setSymbol) - #69

Open
AlecuDimitri wants to merge 1 commit into
LewisWJackson:mainfrom
AlecuDimitri:fix/wait-symbol-detection
Open

Fix symbol detection in waitForChartReady (~8x faster setSymbol)#69
AlecuDimitri wants to merge 1 commit into
LewisWJackson:mainfrom
AlecuDimitri:fix/wait-symbol-detection

Conversation

@AlecuDimitri

Copy link
Copy Markdown

Problem

waitForChartReady reads the current symbol from the DOM legend title ([data-name="legend-source-title"]). That element shows the instrument description (e.g. Gold Spot / U.S. Dollar), not the ticker. When the expected symbol is exchange-prefixed (e.g. OANDA:GBPUSD), the includes() comparison never matches, so every symbol change waits out the full 10s timeout before returning.

Fix

  1. Read the current symbol from the chart API first — window.TradingViewApi._activeChartWidgetWV.value().symbol() returns the real ticker (e.g. OANDA:GBPUSD) — and fall back to the DOM legend if the API isn't available.
  2. Strip the exchange prefix from the expected symbol before comparing (OANDA:GBPUSDGBPUSD), so it still matches when the fallback path returns a bare ticker.

Measurements

before after
setSymbol 10.7s (always hit the timeout) 1.4s

~8x faster, and the wait now actually confirms the symbol switched instead of silently timing out.

🤖 Generated with Claude Code

… exchange prefix

waitForChartReady read the current symbol from the DOM legend title, which
shows the instrument DESCRIPTION (e.g. "Gold Spot / U.S. Dollar"), not the
ticker. Comparing that against an exchange-prefixed symbol like
"OANDA:GBPUSD" never matched, so every setSymbol call waited out the full
10s timeout.

Now the symbol is read from the chart API
(window.TradingViewApi._activeChartWidgetWV.value().symbol(), which returns
e.g. "OANDA:GBPUSD"), with the DOM legend as fallback, and the expected
symbol is compared without its exchange prefix.

Measured: setSymbol went from 10.7s to 1.4s (~8x faster).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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