From e8e1bb83bf9f58b8fe323df8f34e30c0f119520d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20M=C3=B6ller?= Date: Sun, 5 Nov 2023 11:52:09 +0100 Subject: [PATCH] Fix get quotes in CoinGecko service (#2595) * Fix get quotes in CoinGecko service * Update changelog --------- Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com> --- CHANGELOG.md | 1 + .../coingecko/coingecko.service.ts | 20 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef64f6749..ce262a7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue to get quotes in the _CoinGecko_ service - Loosened the validation in the activities import (expects values greater than or equal to 0 for `fee`, `quantity` and `unitPrice`) - Handled an issue with a failing database query (`account.findMany()`) related to activities without account diff --git a/apps/api/src/services/data-provider/coingecko/coingecko.service.ts b/apps/api/src/services/data-provider/coingecko/coingecko.service.ts index b7b571836..3e93d42bf 100644 --- a/apps/api/src/services/data-provider/coingecko/coingecko.service.ts +++ b/apps/api/src/services/data-provider/coingecko/coingecko.service.ts @@ -152,7 +152,7 @@ export class CoinGeckoService implements DataProviderInterface { abortController.abort(); }, DEFAULT_REQUEST_TIMEOUT); - const response = await got( + const quotes = await got( `${this.URL}/simple/price?ids=${symbols.join( ',' )}&vs_currencies=${DEFAULT_CURRENCY.toLowerCase()}`, @@ -162,16 +162,14 @@ export class CoinGeckoService implements DataProviderInterface { } ).json(); - for (const symbol in response) { - if (Object.prototype.hasOwnProperty.call(response, symbol)) { - response[symbol] = { - currency: DEFAULT_CURRENCY, - dataProviderInfo: this.getDataProviderInfo(), - dataSource: DataSource.COINGECKO, - marketPrice: response[symbol][DEFAULT_CURRENCY.toLowerCase()], - marketState: 'open' - }; - } + for (const symbol in quotes) { + response[symbol] = { + currency: DEFAULT_CURRENCY, + dataProviderInfo: this.getDataProviderInfo(), + dataSource: DataSource.COINGECKO, + marketPrice: quotes[symbol][DEFAULT_CURRENCY.toLowerCase()], + marketState: 'open' + }; } } catch (error) { Logger.error(error, 'CoinGeckoService');