(symbol: string)
| 213 | }; |
| 214 | |
| 215 | export 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 | } |
no outgoing calls
no test coverage detected