Bugfix/only allow supported currencies in symbol search (#287)
* Only allow supported currencies in symbol search * Update changelog
This commit is contained in:
@ -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 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 snack bar background color in dark mode
|
||||||
|
- Fixed the search functionality for symbols (filter for supported currencies)
|
||||||
|
|
||||||
## 1.36.0 - 09.08.2021
|
## 1.36.0 - 09.08.2021
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
} from '@ghostfolio/common/helper';
|
} from '@ghostfolio/common/helper';
|
||||||
import { Granularity } from '@ghostfolio/common/types';
|
import { Granularity } from '@ghostfolio/common/types';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { AssetClass, DataSource } from '@prisma/client';
|
import { AssetClass, Currency, DataSource } from '@prisma/client';
|
||||||
import * as bent from 'bent';
|
import * as bent from 'bent';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import * as yahooFinance from 'yahoo-finance';
|
import * as yahooFinance from 'yahoo-finance';
|
||||||
@ -147,8 +147,23 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
200
|
200
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await get();
|
const searchResult = await get();
|
||||||
items = result.quotes
|
|
||||||
|
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) => {
|
.filter((quote) => {
|
||||||
return quote.isYahooFinance;
|
return quote.isYahooFinance;
|
||||||
})
|
})
|
||||||
@ -162,7 +177,12 @@ export class YahooFinanceService implements DataProviderInterface {
|
|||||||
.filter(({ quoteType, symbol }) => {
|
.filter(({ quoteType, symbol }) => {
|
||||||
if (quoteType === 'CRYPTOCURRENCY') {
|
if (quoteType === 'CRYPTOCURRENCY') {
|
||||||
// Only allow cryptocurrencies in USD
|
// 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;
|
return true;
|
||||||
|
@ -166,7 +166,7 @@
|
|||||||
color="primary"
|
color="primary"
|
||||||
i18n
|
i18n
|
||||||
mat-flat-button
|
mat-flat-button
|
||||||
[disabled]="!(addTransactionForm.form.valid && data.transaction.symbol)"
|
[disabled]="!(addTransactionForm.form.valid && data.transaction.currency && data.transaction.symbol)"
|
||||||
[mat-dialog-close]="data"
|
[mat-dialog-close]="data"
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
|
Reference in New Issue
Block a user