Browse Source

Bugfix/only allow supported currencies in symbol search (#287)

* Only allow supported currencies in symbol search

* Update changelog
pull/288/head
Thomas 3 years ago
committed by GitHub
parent
commit
96a615dc5d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 28
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
  3. 2
      apps/client/src/app/pages/portfolio/transactions/create-or-update-transaction-dialog/create-or-update-transaction-dialog.html

1
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

28
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;

2
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

Loading…
Cancel
Save