Skip to content

Fix: Add symbol format conversion for A-Share/HK stocks in TradingVie…#57

Merged
ravixalgorithm merged 4 commits into
Open-Dev-Society:mainfrom
CrixusWen:fix/tradingview-symbol-format
Feb 13, 2026
Merged

Fix: Add symbol format conversion for A-Share/HK stocks in TradingVie…#57
ravixalgorithm merged 4 commits into
Open-Dev-Society:mainfrom
CrixusWen:fix/tradingview-symbol-format

Conversation

@CrixusWen

@CrixusWen CrixusWen commented Feb 12, 2026

Copy link
Copy Markdown

Title: Fix TradingView widget invalid symbol issue for non-US markets

Description: Finnhub returns symbols like 600519.SS (Shanghai) or 000001.SZ (Shenzhen), but TradingView widgets expect SSE:600519 or SZSE:000001.

This PR adds a utility function
formatSymbolForTradingView
to handle this conversion automatically, fixing the "Invalid Symbol" error for A-share and HK stocks.

Summary by CodeRabbit

  • Improvements
    • Improved symbol formatting for international stocks so TradingView widgets on the stock detail page display correct exchange-prefixed symbols (including China and Hong Kong).
    • Watchlist entries now display and use the formatted symbols for consistent display and widget integration.

@vercel

vercel Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the ravixalgorithm's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Feb 12, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds a formatter formatSymbolForTradingView() to lib/utils.ts and replaces raw ticker strings with formatted tvSymbol in TradingView widget inputs on the stock detail page and the watchlist component.

Changes

Cohort / File(s) Summary
Symbol Formatting Utility
lib/utils.ts
Adds export function formatSymbolForTradingView(symbol: string): string — uppercases input, returns empty string for falsy input, maps .SSSSE:, .SZSZSE:, .HKHKEX:; otherwise returns uppercased symbol.
Stock Detail Page
app/(root)/stocks/[symbol]/page.tsx
Imports formatter and replaces direct symbol with computed tvSymbol for all TradingView widget configurations (symbol-info, advanced-chart, baseline, technical-analysis, company-profile, financials).
Watchlist Component
components/watchlist/TradingViewWatchlist.tsx
Uses formatSymbolForTradingView(s) when mapping watchlist items to TradingView name fields, replacing raw symbol usage.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I nibbled at strings, made symbols bright,
Capitals marching, exchanges in sight.
SSE and SZSE, HKEX too,
Widgets now know just what to do —
A rabbit’s tidy formatting flight.

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding symbol format conversion for A-Share and HK stocks in TradingView widgets, which directly addresses the core objective of the PR.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@lib/utils.ts`:
- Around line 157-158: The guard in formatSymbolForTradingView currently returns
the falsy input (which can be null/undefined) even though the function is
declared to return a string; change the guard to return an explicit empty string
('') when symbol is falsy so the function always returns a string; update the
early-return in formatSymbolForTradingView to return '' instead of symbol and
ensure any downstream logic expecting a string continues to work.
🧹 Nitpick comments (1)
lib/utils.ts (1)

162-174: String.replace is not anchored to the end — use slice for suffix removal.

.replace('.SS', '') removes the first occurrence, not necessarily the suffix. After an endsWith check, slice(0, -3) (or -3 for .SS/.SZ/.HK) is more precise and avoids any edge-case mismatch.

Proposed fix
     // Shanghai
     if (upperSymbol.endsWith('.SS')) {
-        return `SSE:${upperSymbol.replace('.SS', '')}`;
+        return `SSE:${upperSymbol.slice(0, -3)}`;
     }
     
     // Shenzhen
     if (upperSymbol.endsWith('.SZ')) {
-        return `SZSE:${upperSymbol.replace('.SZ', '')}`;
+        return `SZSE:${upperSymbol.slice(0, -3)}`;
     }
     
     // Hong Kong
     if (upperSymbol.endsWith('.HK')) {
-        return `HKEX:${upperSymbol.replace('.HK', '')}`;
+        return `HKEX:${upperSymbol.slice(0, -3)}`;
     }

Comment thread lib/utils.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes TradingView widget “Invalid Symbol” issues for non‑US equities by converting Finnhub market suffix symbols (e.g., 600519.SS, 000001.SZ, 0700.HK) into TradingView’s expected exchange‑prefixed format (e.g., SSE:600519, SZSE:000001, HKEX:0700).

Changes:

  • Added formatSymbolForTradingView() utility to convert .SS/.SZ/.HK symbols into TradingView exchange-prefixed symbols.
  • Updated the watchlist TradingView embed to use the formatted symbol for the widget input.
  • Updated the stock detail page TradingView widgets to use the formatted symbol across all widget configs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
lib/utils.ts Adds a symbol conversion helper for TradingView-compatible symbols.
components/watchlist/TradingViewWatchlist.tsx Applies the formatted symbol to the TradingView market-quotes widget input.
app/(root)/stocks/[symbol]/page.tsx Uses the formatted symbol for all embedded TradingView widgets on the stock detail page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 3 to +5
import React, { useEffect, useRef, memo } from 'react';
import { useTheme } from "next-themes";
import { formatSymbolForTradingView } from '@/lib/utils';

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useTheme is imported but never used in this component. This will fail ESLint/TypeScript no-unused-vars checks; remove the import or actually use it to set the TradingView widget theme dynamically.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines 29 to 32
const symbolList = symbols.map(s => ({
name: s,
name: formatSymbolForTradingView(s),
displayName: s
}));

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This watchlist widget still uses the unformatted raw symbol as displayName while only name is formatted. If the intent is that watchlist entries “show and use” the formatted TradingView symbols (per PR description), displayName should also use formatSymbolForTradingView(s) (or the PR description should be updated).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment thread lib/utils.ts Outdated
Comment on lines +163 to +173
return `SSE:${upperSymbol.replace('.SS', '')}`;
}

// Shenzhen
if (upperSymbol.endsWith('.SZ')) {
return `SZSE:${upperSymbol.replace('.SZ', '')}`;
}

// Hong Kong
if (upperSymbol.endsWith('.HK')) {
return `HKEX:${upperSymbol.replace('.HK', '')}`;

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upperSymbol.replace('.SS', '') (and the similar .SZ/.HK cases) removes the first occurrence, not necessarily the suffix you just checked for. Prefer stripping only the trailing market suffix (e.g., with a suffix slice or a /\.SS$/-style replacement) so symbols containing the substring earlier don’t produce incorrect output.

Suggested change
return `SSE:${upperSymbol.replace('.SS', '')}`;
}
// Shenzhen
if (upperSymbol.endsWith('.SZ')) {
return `SZSE:${upperSymbol.replace('.SZ', '')}`;
}
// Hong Kong
if (upperSymbol.endsWith('.HK')) {
return `HKEX:${upperSymbol.replace('.HK', '')}`;
return `SSE:${upperSymbol.slice(0, -3)}`;
}
// Shenzhen
if (upperSymbol.endsWith('.SZ')) {
return `SZSE:${upperSymbol.slice(0, -3)}`;
}
// Hong Kong
if (upperSymbol.endsWith('.HK')) {
return `HKEX:${upperSymbol.slice(0, -3)}`;

Copilot uses AI. Check for mistakes.
@ravixalgorithm ravixalgorithm merged commit 08304b5 into Open-Dev-Society:main Feb 13, 2026
1 of 2 checks passed
@ravixalgorithm

Copy link
Copy Markdown
Member

@CrixusWen Thanks a lot for fixing and opening the PR, really appreciated

stazdev pushed a commit to stazdev/OpenStock that referenced this pull request May 29, 2026
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.

3 participants