diff --git a/.vscode/launch.json b/.vscode/launch.json index c1f19e7f0..e7f2c5659 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,7 @@ "name": "Debug Jest", "program": "${workspaceFolder}/node_modules/@nrwl/cli/bin/nx", "request": "launch", + "runtimeExecutable": "/Users/ddgs/.nvm/versions/node/v22.18.0/bin/node", "type": "node" }, { @@ -24,6 +25,7 @@ "program": "${workspaceFolder}/apps/api/src/main.ts", "request": "launch", "runtimeArgs": ["--nolazy", "-r", "ts-node/register"], + "runtimeExecutable": "/Users/ddgs/.nvm/versions/node/v22.18.0/bin/node", "skipFiles": [ "${workspaceFolder}/node_modules/**/*.js", "/**/*.js" diff --git a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts index de8807098..39f82091d 100644 --- a/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts +++ b/apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts @@ -80,19 +80,24 @@ export class YahooFinanceService implements DataProviderInterface { } try { - const historicalResult = this.convertToDividendResult( - await this.yahooFinance.chart( - this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( - symbol - ), - { - events: 'dividends', - interval: granularity === 'month' ? '1mo' : '1d', - period1: format(from, DATE_FORMAT), - period2: format(to, DATE_FORMAT) - } - ) + const chartResponse = await this.yahooFinance.chart( + this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( + symbol + ), + { + events: 'dividends', + interval: granularity === 'month' ? '1mo' : '1d', + period1: format(from, DATE_FORMAT), + period2: format(to, DATE_FORMAT) + } ); + + Logger.debug( + `Fetched dividends for ${symbol} from ${format(from, DATE_FORMAT)} to ${format(to, DATE_FORMAT)}: ${chartResponse.events?.dividends?.length ?? 0} entries`, + 'YahooFinanceService' + ); + + const historicalResult = this.convertToDividendResult(chartResponse); const response: { [date: string]: DataProviderHistoricalResponse; } = {}; @@ -129,19 +134,24 @@ export class YahooFinanceService implements DataProviderInterface { } try { - const historicalResult = this.convertToHistoricalResult( - await this.yahooFinance.chart( - this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( - symbol - ), - { - interval: '1d', - period1: format(from, DATE_FORMAT), - period2: format(to, DATE_FORMAT) - } - ) + const chartResponse = await this.yahooFinance.chart( + this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( + symbol + ), + { + interval: '1d', + period1: format(from, DATE_FORMAT), + period2: format(to, DATE_FORMAT) + } ); + Logger.debug( + `Fetched historical market data for ${symbol} from ${format(from, DATE_FORMAT)} to ${format(to, DATE_FORMAT)}: ${chartResponse.quotes?.length ?? 0} quotes`, + 'YahooFinanceService' + ); + + const historicalResult = this.convertToHistoricalResult(chartResponse); + const response: { [symbol: string]: { [date: string]: DataProviderHistoricalResponse }; } = {}; @@ -197,6 +207,11 @@ export class YahooFinanceService implements DataProviderInterface { try { quotes = await this.yahooFinance.quote(yahooFinanceSymbols); + + Logger.debug( + `Fetched quotes for ${yahooFinanceSymbols.length} symbol(s) [${yahooFinanceSymbols.join(', ')}]: ${quotes.length} results`, + 'YahooFinanceService' + ); } catch (error) { Logger.error(error, 'YahooFinanceService'); @@ -206,6 +221,11 @@ export class YahooFinanceService implements DataProviderInterface { ); quotes = await this.getQuotesWithQuoteSummary(yahooFinanceSymbols); + + Logger.debug( + `Fetched quotes via quoteSummary fallback for ${yahooFinanceSymbols.length} symbol(s) [${yahooFinanceSymbols.join(', ')}]: ${quotes.length} results`, + 'YahooFinanceService' + ); } for (const quote of quotes) { @@ -254,6 +274,11 @@ export class YahooFinanceService implements DataProviderInterface { const searchResult = await this.yahooFinance.search(query); + Logger.debug( + `Fetched search results for query "${query}": ${searchResult.quotes?.length ?? 0} quotes`, + 'YahooFinanceService' + ); + const quotes = searchResult.quotes .filter( (quote): quote is Exclude => { @@ -296,6 +321,11 @@ export class YahooFinanceService implements DataProviderInterface { return symbol; }) ); + + Logger.debug( + `Fetched market data for search results of query "${query}": ${marketData.length} quotes`, + 'YahooFinanceService' + ); } catch (error) { if (error?.result?.length > 0) { marketData = error.result; @@ -361,6 +391,16 @@ export class YahooFinanceService implements DataProviderInterface { const settledResults = await Promise.allSettled(quoteSummaryPromises); + const fulfilled = settledResults.filter( + (result) => result.status === 'fulfilled' + ).length; + const rejected = settledResults.length - fulfilled; + + Logger.debug( + `Fetched quoteSummary for ${aYahooFinanceSymbols.length} symbol(s) [${aYahooFinanceSymbols.join(', ')}]: ${fulfilled} fulfilled, ${rejected} rejected`, + 'YahooFinanceService' + ); + return settledResults .filter( (result): result is PromiseFulfilledResult => { diff --git a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts index 024bdf4e1..8e50666a6 100644 --- a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts @@ -294,6 +294,8 @@ export class ExchangeRateDataService { date: aDate }); + console.log('===> hay marketData ?? ', marketData?.marketPrice); + if (marketData?.marketPrice) { factor = marketData?.marketPrice; } else { @@ -313,6 +315,10 @@ export class ExchangeRateDataService { symbol: `${DEFAULT_CURRENCY}${aFromCurrency}` }) )?.marketPrice; + console.log( + '===> marketPriceBaseCurrencyFromCurrency', + marketPriceBaseCurrencyFromCurrency + ); } } catch {} @@ -327,6 +333,10 @@ export class ExchangeRateDataService { symbol: `${DEFAULT_CURRENCY}${aToCurrency}` }) )?.marketPrice; + console.log( + '===> marketPriceBaseCurrencyToCurrency', + marketPriceBaseCurrencyToCurrency + ); } } catch {} diff --git a/package.json b/package.json index e8b38049b..a32bd9cb3 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "prisma": "prisma", "replace-placeholders-in-build": "node ./replace.build.mjs", "start": "node dist/apps/api/main", - "start:client": "nx run client:copy-assets && nx run client:serve --configuration=development-en --hmr -o", + "start:client": "nx run client:copy-assets && nx run client:serve --configuration=development-es --hmr -o", "start:production": "npm run database:migrate && npm run database:seed && node main", "start:server": "nx run api:copy-assets && nx run api:serve --watch", "start:storybook": "nx run ui:storybook",