diff --git a/CHANGELOG.md b/CHANGELOG.md index 5af076a0..92e6ba36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed the position detail chart if there are missing historical data around the first buy date - Fixed the snack bar background color in dark mode +- Fixed the search functionality for symbols (filter for supported currencies) ## 1.36.0 - 09.08.2021 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 07998d76..93e601ca 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 @@ -8,7 +8,7 @@ import { } from '@ghostfolio/common/helper'; import { Granularity } from '@ghostfolio/common/types'; import { Injectable } from '@nestjs/common'; -import { AssetClass, DataSource } from '@prisma/client'; +import { AssetClass, Currency, DataSource } from '@prisma/client'; import * as bent from 'bent'; import { format } from 'date-fns'; import * as yahooFinance from 'yahoo-finance'; @@ -147,8 +147,23 @@ export class YahooFinanceService implements DataProviderInterface { 200 ); - const result = await get(); - items = result.quotes + const searchResult = await get(); + + const symbols: string[] = searchResult.quotes + .filter((quote) => { + // filter out undefined symbols + return quote.symbol; + }) + .filter(({ quoteType }) => { + return quoteType === 'EQUITY' || quoteType === 'ETF'; + }) + .map(({ symbol }) => { + return symbol; + }); + + const marketData = await this.get(symbols); + + items = searchResult.quotes .filter((quote) => { return quote.isYahooFinance; }) @@ -162,7 +177,12 @@ export class YahooFinanceService implements DataProviderInterface { .filter(({ quoteType, symbol }) => { if (quoteType === 'CRYPTOCURRENCY') { // Only allow cryptocurrencies in USD - return symbol.includes('USD'); + return symbol.includes(Currency.USD); + } + + if (!marketData[symbol]?.currency) { + // Only allow symbols with supported currency + return false; } return true; diff --git a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html index eb4205a7..a183b9ce 100644 --- a/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html +++ b/apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html @@ -166,7 +166,7 @@ color="primary" i18n mat-flat-button - [disabled]="!(addTransactionForm.form.valid && data.transaction.symbol)" + [disabled]="!(addTransactionForm.form.valid && data.transaction.currency && data.transaction.symbol)" [mat-dialog-close]="data" > Save