(
symbol: string,
provider: MarketProvider,
apiKey?: string,
)
| 178 | |
| 179 | // --- Dispatcher --- |
| 180 | async function fetchSymbol( |
| 181 | symbol: string, |
| 182 | provider: MarketProvider, |
| 183 | apiKey?: string, |
| 184 | ): Promise<MarketQuote> { |
| 185 | const hasPermission = await checkHostPermission(provider); |
| 186 | if (!hasPermission) throw new Error('Host permission not granted'); |
| 187 | |
| 188 | switch (provider) { |
| 189 | case 'finnhub': |
| 190 | if (!apiKey) throw new Error('Finnhub requires an API key'); |
| 191 | return fetchFinnhub(symbol, apiKey); |
| 192 | case 'twelvedata': |
| 193 | if (!apiKey) throw new Error('Twelve Data requires an API key'); |
| 194 | return fetchTwelveData(symbol, apiKey); |
| 195 | case 'yahoo': |
| 196 | default: |
| 197 | return fetchYahoo(symbol); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // --- Hook --- |
| 202 | export function useMarketData( |
no test coverage detected