From 80782f1098ab31be40326584149a088f905a1b32 Mon Sep 17 00:00:00 2001 From: Valentin Zickner <3200232+vzickner@users.noreply.github.com> Date: Sun, 21 Nov 2021 11:38:48 -0500 Subject: [PATCH] =?UTF-8?q?add=20support=20for=20euro=20cryptocurrencies,?= =?UTF-8?q?=20ALGO=20and=20remove=20unknown=20crypto=E2=80=A6=20(#480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add support for euro cryptocurrencies, ALGO and remove unknown cryptocurrencies from list * Update changelog Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com> --- CHANGELOG.md | 8 ++++++++ .../cryptocurrency/custom-cryptocurrencies.json | 1 + .../yahoo-finance/yahoo-finance.service.ts | 17 +++++++++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22ba4d9fe..958a49530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Added support for cryptocurrency _Algorand_ + ### Changed - Locked the symbol input in the edit transaction dialog - Filtered the account selector by account type (`SECURITIES`) in the create or edit transaction dialog +### Fixed + +- Fixed the search functionality for cryptocurrency symbols (do not show unsupported symbols) + ## 1.78.0 - 20.11.2021 ### Added diff --git a/apps/api/src/services/cryptocurrency/custom-cryptocurrencies.json b/apps/api/src/services/cryptocurrency/custom-cryptocurrencies.json index 3e181c6a7..949b455db 100644 --- a/apps/api/src/services/cryptocurrency/custom-cryptocurrencies.json +++ b/apps/api/src/services/cryptocurrency/custom-cryptocurrencies.json @@ -1,5 +1,6 @@ { "1INCH": "1inch", + "ALGO": "Algorand", "AVAX": "Avalanche", "MATIC": "Polygon", "SHIB": "Shiba Inu" 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 2fac41b47..4079b437b 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 @@ -197,16 +197,20 @@ export class YahooFinanceService implements DataProviderInterface { // filter out undefined symbols return quote.symbol; }) - .filter(({ quoteType }) => { + .filter(({ quoteType, symbol }) => { return ( - quoteType === 'CRYPTOCURRENCY' || + (quoteType === 'CRYPTOCURRENCY' && + this.cryptocurrencyService.isCrypto( + symbol.replace(new RegExp('-USD$'), 'USD').replace('1', '') + )) || quoteType === 'EQUITY' || quoteType === 'ETF' ); }) .filter(({ quoteType, symbol }) => { if (quoteType === 'CRYPTOCURRENCY') { - // Only allow cryptocurrencies in USD + // Only allow cryptocurrencies in USD to avoid having redundancy in the database. + // Trades need to be converted manually before to USD (or a UI converter needs to be developed) return symbol.includes('USD'); } @@ -254,14 +258,15 @@ export class YahooFinanceService implements DataProviderInterface { if (isCurrency(aSymbol.substring(0, aSymbol.length - 3))) { return `${aSymbol}=X`; } else if ( - this.cryptocurrencyService.isCrypto(aSymbol) || - this.cryptocurrencyService.isCrypto(aSymbol.replace('1', '')) + this.cryptocurrencyService.isCrypto( + aSymbol.replace(new RegExp('-USD$'), 'USD').replace('1', '') + ) ) { // Add a dash before the last three characters // BTCUSD -> BTC-USD // DOGEUSD -> DOGE-USD // SOL1USD -> SOL1-USD - return aSymbol.replace('USD', '-USD'); + return aSymbol.replace(new RegExp('-?USD$'), '-USD'); } }