Bugfix/Use currency conversion for fees and values (#3672)

* Use currency conversion for fees and values

* Update changelog
pull/3682/head
Anatoly Popov 3 months ago committed by GitHub
parent 6c79ccb2a9
commit 12c722afe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Fixed the currency conversion for fees and values in the dividend import by applying the correct rate based on the activity date
- Fixed the currency conversion for fees and values in the activities service by applying the correct rate based on the activity date
## 2.104.1 - 2024-08-17 ## 2.104.1 - 2024-08-17
### Fixed ### Fixed

@ -82,7 +82,8 @@ export class ImportService {
const Account = this.isUniqueAccount(accounts) ? accounts[0] : undefined; const Account = this.isUniqueAccount(accounts) ? accounts[0] : undefined;
return Object.entries(dividends).map(([dateString, { marketPrice }]) => { return await Promise.all(
Object.entries(dividends).map(async ([dateString, { marketPrice }]) => {
const quantity = const quantity =
historicalData.find((historicalDataItem) => { historicalData.find((historicalDataItem) => {
return historicalDataItem.date === dateString; return historicalDataItem.date === dateString;
@ -129,13 +130,16 @@ export class ImportService {
unitPrice: marketPrice, unitPrice: marketPrice,
updatedAt: undefined, updatedAt: undefined,
userId: Account?.userId, userId: Account?.userId,
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( valueInBaseCurrency:
await this.exchangeRateDataService.toCurrencyAtDate(
value, value,
assetProfile.currency, assetProfile.currency,
userCurrency userCurrency,
date
) )
}; };
}); })
);
} catch { } catch {
return []; return [];
} }
@ -432,17 +436,20 @@ export class ImportService {
...order, ...order,
error, error,
value, value,
feeInBaseCurrency: this.exchangeRateDataService.toCurrency( feeInBaseCurrency: await this.exchangeRateDataService.toCurrencyAtDate(
fee, fee,
assetProfile.currency, assetProfile.currency,
userCurrency userCurrency,
date
), ),
// @ts-ignore // @ts-ignore
SymbolProfile: assetProfile, SymbolProfile: assetProfile,
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( valueInBaseCurrency:
await this.exchangeRateDataService.toCurrencyAtDate(
value, value,
assetProfile.currency, assetProfile.currency,
userCurrency userCurrency,
date
) )
}); });
} }

@ -483,7 +483,8 @@ export class OrderService {
assetProfileIdentifiers assetProfileIdentifiers
); );
const activities = orders.map((order) => { const activities = await Promise.all(
orders.map(async (order) => {
const assetProfile = assetProfiles.find(({ dataSource, symbol }) => { const assetProfile = assetProfiles.find(({ dataSource, symbol }) => {
return ( return (
dataSource === order.SymbolProfile.dataSource && dataSource === order.SymbolProfile.dataSource &&
@ -496,21 +497,24 @@ export class OrderService {
return { return {
...order, ...order,
value, value,
// TODO: Use exchange rate of date feeInBaseCurrency:
feeInBaseCurrency: this.exchangeRateDataService.toCurrency( await this.exchangeRateDataService.toCurrencyAtDate(
order.fee, order.fee,
order.SymbolProfile.currency, order.SymbolProfile.currency,
userCurrency userCurrency,
order.date
), ),
SymbolProfile: assetProfile, SymbolProfile: assetProfile,
// TODO: Use exchange rate of date valueInBaseCurrency:
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( await this.exchangeRateDataService.toCurrencyAtDate(
value, value,
order.SymbolProfile.currency, order.SymbolProfile.currency,
userCurrency userCurrency,
order.date
) )
}; };
}); })
);
return { activities, count }; return { activities, count };
} }

Loading…
Cancel
Save