Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Simplify search (#828)

Thomas Kaul65e062ad26c3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2eff35556f..8070c45269 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support to export future activities (drafts) as `.ics` files
+### Changed
+
+- Migrated the search functionality to `yahoo-finance2`
+
## 1.136.0 - 13.04.2022
### Changed
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 ef4328fc83..b5a0932fbc 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
@@ -16,7 +16,6 @@ import {
DataSource,
SymbolProfile
} from '@prisma/client';
-import * as bent from 'bent';
import Big from 'big.js';
import { countries } from 'countries-list';
import { addDays, format, isSameDay } from 'date-fns';
@@ -25,8 +24,6 @@ import type { Price } from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-ifa
@Injectable()
export class YahooFinanceService implements DataProviderInterface {
- private readonly yahooFinanceHostname = 'https://query1.finance.yahoo.com';
-
public constructor(
private readonly cryptocurrencyService: CryptocurrencyService
) {}
@@ -244,16 +241,7 @@ export class YahooFinanceService implements DataProviderInterface {
const items: LookupItem[] = [];
try {
- const get = bent(
- `${this.yahooFinanceHostname}/v1/finance/search?q=${encodeURIComponent(
- aQuery
- )}&lang=en-US&region=US&quotesCount=8&newsCount=0&enableFuzzyQuery=false&quotesQueryId=tss_match_phrase_query&multiQuoteQueryId=multi_quote_single_token_query&newsQueryId=news_cie_vespa&enableCb=true&enableNavLinks=false&enableEnhancedTrivialQuery=true`,
- 'GET',
- 'json',
- 200
- );
-
- const searchResult = await get();
+ const searchResult = await yahooFinance.search(aQuery);
const quotes = searchResult.quotes
.filter((quote) => {
@@ -279,20 +267,24 @@ export class YahooFinanceService implements DataProviderInterface {
return true;
});
- const marketData = await this.getQuotes(
+ const marketData = await yahooFinance.quote(
quotes.map(({ symbol }) => {
return symbol;
})
);
- for (const [symbol, value] of Object.entries(marketData)) {
- const quote = quotes.find((currentQuote: any) => {
- return currentQuote.symbol === symbol;
+ for (const marketDataItem of marketData) {
+ const quote = quotes.find((currentQuote) => {
+ return currentQuote.symbol === marketDataItem.symbol;
});
+ const symbol = this.convertFromYahooFinanceSymbol(
+ marketDataItem.symbol
+ );
+
items.push({
symbol,
- currency: value.currency,
+ currency: marketDataItem.currency,
dataSource: this.getName(),
name: quote?.longname || quote?.shortname || symbol
});