|
|
@ -82,60 +82,64 @@ 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(
|
|
|
|
const quantity =
|
|
|
|
Object.entries(dividends).map(async ([dateString, { marketPrice }]) => {
|
|
|
|
historicalData.find((historicalDataItem) => {
|
|
|
|
const quantity =
|
|
|
|
return historicalDataItem.date === dateString;
|
|
|
|
historicalData.find((historicalDataItem) => {
|
|
|
|
})?.quantity ?? 0;
|
|
|
|
return historicalDataItem.date === dateString;
|
|
|
|
|
|
|
|
})?.quantity ?? 0;
|
|
|
|
const value = new Big(quantity).mul(marketPrice).toNumber();
|
|
|
|
|
|
|
|
|
|
|
|
const value = new Big(quantity).mul(marketPrice).toNumber();
|
|
|
|
const date = parseDate(dateString);
|
|
|
|
|
|
|
|
const isDuplicate = orders.some((activity) => {
|
|
|
|
const date = parseDate(dateString);
|
|
|
|
return (
|
|
|
|
const isDuplicate = orders.some((activity) => {
|
|
|
|
activity.accountId === Account?.id &&
|
|
|
|
return (
|
|
|
|
activity.SymbolProfile.currency === assetProfile.currency &&
|
|
|
|
activity.accountId === Account?.id &&
|
|
|
|
activity.SymbolProfile.dataSource === assetProfile.dataSource &&
|
|
|
|
activity.SymbolProfile.currency === assetProfile.currency &&
|
|
|
|
isSameSecond(activity.date, date) &&
|
|
|
|
activity.SymbolProfile.dataSource === assetProfile.dataSource &&
|
|
|
|
activity.quantity === quantity &&
|
|
|
|
isSameSecond(activity.date, date) &&
|
|
|
|
activity.SymbolProfile.symbol === assetProfile.symbol &&
|
|
|
|
activity.quantity === quantity &&
|
|
|
|
activity.type === 'DIVIDEND' &&
|
|
|
|
activity.SymbolProfile.symbol === assetProfile.symbol &&
|
|
|
|
activity.unitPrice === marketPrice
|
|
|
|
activity.type === 'DIVIDEND' &&
|
|
|
|
);
|
|
|
|
activity.unitPrice === marketPrice
|
|
|
|
});
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const error: ActivityError = isDuplicate
|
|
|
|
const error: ActivityError = isDuplicate
|
|
|
|
? { code: 'IS_DUPLICATE' }
|
|
|
|
? { code: 'IS_DUPLICATE' }
|
|
|
|
: undefined;
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
Account,
|
|
|
|
Account,
|
|
|
|
date,
|
|
|
|
date,
|
|
|
|
error,
|
|
|
|
error,
|
|
|
|
quantity,
|
|
|
|
quantity,
|
|
|
|
value,
|
|
|
|
|
|
|
|
accountId: Account?.id,
|
|
|
|
|
|
|
|
accountUserId: undefined,
|
|
|
|
|
|
|
|
comment: undefined,
|
|
|
|
|
|
|
|
currency: undefined,
|
|
|
|
|
|
|
|
createdAt: undefined,
|
|
|
|
|
|
|
|
fee: 0,
|
|
|
|
|
|
|
|
feeInBaseCurrency: 0,
|
|
|
|
|
|
|
|
id: assetProfile.id,
|
|
|
|
|
|
|
|
isDraft: false,
|
|
|
|
|
|
|
|
SymbolProfile: assetProfile,
|
|
|
|
|
|
|
|
symbolProfileId: assetProfile.id,
|
|
|
|
|
|
|
|
type: 'DIVIDEND',
|
|
|
|
|
|
|
|
unitPrice: marketPrice,
|
|
|
|
|
|
|
|
updatedAt: undefined,
|
|
|
|
|
|
|
|
userId: Account?.userId,
|
|
|
|
|
|
|
|
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
|
|
|
|
|
|
|
value,
|
|
|
|
value,
|
|
|
|
assetProfile.currency,
|
|
|
|
accountId: Account?.id,
|
|
|
|
userCurrency
|
|
|
|
accountUserId: undefined,
|
|
|
|
)
|
|
|
|
comment: undefined,
|
|
|
|
};
|
|
|
|
currency: undefined,
|
|
|
|
});
|
|
|
|
createdAt: undefined,
|
|
|
|
|
|
|
|
fee: 0,
|
|
|
|
|
|
|
|
feeInBaseCurrency: 0,
|
|
|
|
|
|
|
|
id: assetProfile.id,
|
|
|
|
|
|
|
|
isDraft: false,
|
|
|
|
|
|
|
|
SymbolProfile: assetProfile,
|
|
|
|
|
|
|
|
symbolProfileId: assetProfile.id,
|
|
|
|
|
|
|
|
type: 'DIVIDEND',
|
|
|
|
|
|
|
|
unitPrice: marketPrice,
|
|
|
|
|
|
|
|
updatedAt: undefined,
|
|
|
|
|
|
|
|
userId: Account?.userId,
|
|
|
|
|
|
|
|
valueInBaseCurrency:
|
|
|
|
|
|
|
|
await this.exchangeRateDataService.toCurrencyAtDate(
|
|
|
|
|
|
|
|
value,
|
|
|
|
|
|
|
|
assetProfile.currency,
|
|
|
|
|
|
|
|
userCurrency,
|
|
|
|
|
|
|
|
date
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
return [];
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -432,18 +436,21 @@ 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:
|
|
|
|
value,
|
|
|
|
await this.exchangeRateDataService.toCurrencyAtDate(
|
|
|
|
assetProfile.currency,
|
|
|
|
value,
|
|
|
|
userCurrency
|
|
|
|
assetProfile.currency,
|
|
|
|
)
|
|
|
|
userCurrency,
|
|
|
|
|
|
|
|
date
|
|
|
|
|
|
|
|
)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|