Browse Source

add logs

pull/6577/head
davidgarciasantes 2 weeks ago
parent
commit
7c42aa76d3
  1. 2
      .vscode/launch.json
  2. 86
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
  3. 10
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
  4. 2
      package.json

2
.vscode/launch.json

@ -12,6 +12,7 @@
"name": "Debug Jest", "name": "Debug Jest",
"program": "${workspaceFolder}/node_modules/@nrwl/cli/bin/nx", "program": "${workspaceFolder}/node_modules/@nrwl/cli/bin/nx",
"request": "launch", "request": "launch",
"runtimeExecutable": "/Users/ddgs/.nvm/versions/node/v22.18.0/bin/node",
"type": "node" "type": "node"
}, },
{ {
@ -24,6 +25,7 @@
"program": "${workspaceFolder}/apps/api/src/main.ts", "program": "${workspaceFolder}/apps/api/src/main.ts",
"request": "launch", "request": "launch",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"], "runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"runtimeExecutable": "/Users/ddgs/.nvm/versions/node/v22.18.0/bin/node",
"skipFiles": [ "skipFiles": [
"${workspaceFolder}/node_modules/**/*.js", "${workspaceFolder}/node_modules/**/*.js",
"<node_internals>/**/*.js" "<node_internals>/**/*.js"

86
apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

@ -80,19 +80,24 @@ export class YahooFinanceService implements DataProviderInterface {
} }
try { try {
const historicalResult = this.convertToDividendResult( const chartResponse = await this.yahooFinance.chart(
await this.yahooFinance.chart( this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( symbol
symbol ),
), {
{ events: 'dividends',
events: 'dividends', interval: granularity === 'month' ? '1mo' : '1d',
interval: granularity === 'month' ? '1mo' : '1d', period1: format(from, DATE_FORMAT),
period1: format(from, DATE_FORMAT), period2: format(to, 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: { const response: {
[date: string]: DataProviderHistoricalResponse; [date: string]: DataProviderHistoricalResponse;
} = {}; } = {};
@ -129,19 +134,24 @@ export class YahooFinanceService implements DataProviderInterface {
} }
try { try {
const historicalResult = this.convertToHistoricalResult( const chartResponse = await this.yahooFinance.chart(
await this.yahooFinance.chart( this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol( symbol
symbol ),
), {
{ interval: '1d',
interval: '1d', period1: format(from, DATE_FORMAT),
period1: format(from, DATE_FORMAT), period2: format(to, 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: { const response: {
[symbol: string]: { [date: string]: DataProviderHistoricalResponse }; [symbol: string]: { [date: string]: DataProviderHistoricalResponse };
} = {}; } = {};
@ -197,6 +207,11 @@ export class YahooFinanceService implements DataProviderInterface {
try { try {
quotes = await this.yahooFinance.quote(yahooFinanceSymbols); quotes = await this.yahooFinance.quote(yahooFinanceSymbols);
Logger.debug(
`Fetched quotes for ${yahooFinanceSymbols.length} symbol(s) [${yahooFinanceSymbols.join(', ')}]: ${quotes.length} results`,
'YahooFinanceService'
);
} catch (error) { } catch (error) {
Logger.error(error, 'YahooFinanceService'); Logger.error(error, 'YahooFinanceService');
@ -206,6 +221,11 @@ export class YahooFinanceService implements DataProviderInterface {
); );
quotes = await this.getQuotesWithQuoteSummary(yahooFinanceSymbols); 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) { for (const quote of quotes) {
@ -254,6 +274,11 @@ export class YahooFinanceService implements DataProviderInterface {
const searchResult = await this.yahooFinance.search(query); 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 const quotes = searchResult.quotes
.filter( .filter(
(quote): quote is Exclude<typeof quote, SearchQuoteNonYahoo> => { (quote): quote is Exclude<typeof quote, SearchQuoteNonYahoo> => {
@ -296,6 +321,11 @@ export class YahooFinanceService implements DataProviderInterface {
return symbol; return symbol;
}) })
); );
Logger.debug(
`Fetched market data for search results of query "${query}": ${marketData.length} quotes`,
'YahooFinanceService'
);
} catch (error) { } catch (error) {
if (error?.result?.length > 0) { if (error?.result?.length > 0) {
marketData = error.result; marketData = error.result;
@ -361,6 +391,16 @@ export class YahooFinanceService implements DataProviderInterface {
const settledResults = await Promise.allSettled(quoteSummaryPromises); 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 return settledResults
.filter( .filter(
(result): result is PromiseFulfilledResult<QuoteSummaryResult> => { (result): result is PromiseFulfilledResult<QuoteSummaryResult> => {

10
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

@ -294,6 +294,8 @@ export class ExchangeRateDataService {
date: aDate date: aDate
}); });
console.log('===> hay marketData ?? ', marketData?.marketPrice);
if (marketData?.marketPrice) { if (marketData?.marketPrice) {
factor = marketData?.marketPrice; factor = marketData?.marketPrice;
} else { } else {
@ -313,6 +315,10 @@ export class ExchangeRateDataService {
symbol: `${DEFAULT_CURRENCY}${aFromCurrency}` symbol: `${DEFAULT_CURRENCY}${aFromCurrency}`
}) })
)?.marketPrice; )?.marketPrice;
console.log(
'===> marketPriceBaseCurrencyFromCurrency',
marketPriceBaseCurrencyFromCurrency
);
} }
} catch {} } catch {}
@ -327,6 +333,10 @@ export class ExchangeRateDataService {
symbol: `${DEFAULT_CURRENCY}${aToCurrency}` symbol: `${DEFAULT_CURRENCY}${aToCurrency}`
}) })
)?.marketPrice; )?.marketPrice;
console.log(
'===> marketPriceBaseCurrencyToCurrency',
marketPriceBaseCurrencyToCurrency
);
} }
} catch {} } catch {}

2
package.json

@ -39,7 +39,7 @@
"prisma": "prisma", "prisma": "prisma",
"replace-placeholders-in-build": "node ./replace.build.mjs", "replace-placeholders-in-build": "node ./replace.build.mjs",
"start": "node dist/apps/api/main", "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:production": "npm run database:migrate && npm run database:seed && node main",
"start:server": "nx run api:copy-assets && nx run api:serve --watch", "start:server": "nx run api:copy-assets && nx run api:serve --watch",
"start:storybook": "nx run ui:storybook", "start:storybook": "nx run ui:storybook",

Loading…
Cancel
Save