MCPcopy Create free account
hub / github.com/Open-Dev-Society/OpenStock / formatSymbolForTradingView

Function formatSymbolForTradingView

lib/utils.ts:215–233  ·  view source on GitHub ↗
(symbol: string)

Source from the content-addressed store, hash-verified

213};
214
215export function formatSymbolForTradingView(symbol: string): string {
216 if (!symbol) return '';
217 const upperSymbol = symbol.toUpperCase();
218
219 // Check for known exchange suffixes, trying longer suffixes first
220 // to avoid ".TWO" matching ".TW" prematurely
221 const suffixes = Object.keys(FINNHUB_TO_TRADINGVIEW_EXCHANGE)
222 .sort((a, b) => b.length - a.length);
223
224 for (const suffix of suffixes) {
225 if (upperSymbol.endsWith(suffix.toUpperCase())) {
226 const ticker = upperSymbol.slice(0, -suffix.length);
227 const exchange = FINNHUB_TO_TRADINGVIEW_EXCHANGE[suffix];
228 return `${exchange}:${ticker}`;
229 }
230 }
231
232 return upperSymbol;
233}

Callers 3

TradingViewWatchlistFunction · 0.90
StockDetailsFunction · 0.90
utils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected