Feature/improve liabilities in portfolio calculator (#3696)
Improve liabilities
This commit is contained in:
parent
a8e0bb5a21
commit
e23019a115
@ -519,6 +519,23 @@ export class OrderService {
|
|||||||
return { activities, count };
|
return { activities, count };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getOrdersForPortfolioCalculator({
|
||||||
|
filters,
|
||||||
|
userCurrency,
|
||||||
|
userId
|
||||||
|
}: {
|
||||||
|
filters?: Filter[];
|
||||||
|
userCurrency: string;
|
||||||
|
userId: string;
|
||||||
|
}) {
|
||||||
|
return this.getOrders({
|
||||||
|
filters,
|
||||||
|
userCurrency,
|
||||||
|
userId,
|
||||||
|
withExcludedAccounts: false // TODO
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async getStatisticsByCurrency(
|
public async getStatisticsByCurrency(
|
||||||
currency: EnhancedSymbolProfile['currency']
|
currency: EnhancedSymbolProfile['currency']
|
||||||
): Promise<{
|
): Promise<{
|
||||||
|
@ -247,13 +247,12 @@ export class PortfolioService {
|
|||||||
|
|
||||||
const { endDate, startDate } = getIntervalFromDateRange(dateRange);
|
const { endDate, startDate } = getIntervalFromDateRange(dateRange);
|
||||||
|
|
||||||
const { activities } = await this.orderService.getOrders({
|
const { activities } =
|
||||||
filters,
|
await this.orderService.getOrdersForPortfolioCalculator({
|
||||||
userId,
|
filters,
|
||||||
includeDrafts: true,
|
userId,
|
||||||
types: ['BUY', 'SELL'],
|
userCurrency: this.getUserCurrency()
|
||||||
userCurrency: this.getUserCurrency()
|
});
|
||||||
});
|
|
||||||
|
|
||||||
if (activities.length === 0) {
|
if (activities.length === 0) {
|
||||||
return {
|
return {
|
||||||
@ -332,12 +331,12 @@ export class PortfolioService {
|
|||||||
(user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
|
(user.Settings?.settings as UserSettings)?.emergencyFund ?? 0
|
||||||
);
|
);
|
||||||
|
|
||||||
const { activities } = await this.orderService.getOrders({
|
const { activities } =
|
||||||
filters,
|
await this.orderService.getOrdersForPortfolioCalculator({
|
||||||
userCurrency,
|
filters,
|
||||||
userId,
|
userCurrency,
|
||||||
withExcludedAccounts
|
userId
|
||||||
});
|
});
|
||||||
|
|
||||||
const portfolioCalculator = this.calculatorFactory.createCalculator({
|
const portfolioCalculator = this.calculatorFactory.createCalculator({
|
||||||
activities,
|
activities,
|
||||||
@ -597,11 +596,11 @@ export class PortfolioService {
|
|||||||
const user = await this.userService.user({ id: userId });
|
const user = await this.userService.user({ id: userId });
|
||||||
const userCurrency = this.getUserCurrency(user);
|
const userCurrency = this.getUserCurrency(user);
|
||||||
|
|
||||||
const { activities } = await this.orderService.getOrders({
|
const { activities } =
|
||||||
userCurrency,
|
await this.orderService.getOrdersForPortfolioCalculator({
|
||||||
userId,
|
userCurrency,
|
||||||
withExcludedAccounts: true
|
userId
|
||||||
});
|
});
|
||||||
|
|
||||||
const orders = activities.filter(({ SymbolProfile }) => {
|
const orders = activities.filter(({ SymbolProfile }) => {
|
||||||
return (
|
return (
|
||||||
@ -906,14 +905,12 @@ export class PortfolioService {
|
|||||||
const userId = await this.getUserId(impersonationId, this.request.user.id);
|
const userId = await this.getUserId(impersonationId, this.request.user.id);
|
||||||
const user = await this.userService.user({ id: userId });
|
const user = await this.userService.user({ id: userId });
|
||||||
|
|
||||||
const { endDate } = getIntervalFromDateRange(dateRange);
|
const { activities } =
|
||||||
|
await this.orderService.getOrdersForPortfolioCalculator({
|
||||||
const { activities } = await this.orderService.getOrders({
|
filters,
|
||||||
endDate,
|
userId,
|
||||||
filters,
|
userCurrency: this.getUserCurrency()
|
||||||
userId,
|
});
|
||||||
userCurrency: this.getUserCurrency()
|
|
||||||
});
|
|
||||||
|
|
||||||
if (activities?.length <= 0) {
|
if (activities?.length <= 0) {
|
||||||
return {
|
return {
|
||||||
@ -1085,15 +1082,12 @@ export class PortfolioService {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const { endDate, startDate } = getIntervalFromDateRange(dateRange);
|
const { activities } =
|
||||||
|
await this.orderService.getOrdersForPortfolioCalculator({
|
||||||
const { activities } = await this.orderService.getOrders({
|
filters,
|
||||||
endDate,
|
userCurrency,
|
||||||
filters,
|
userId
|
||||||
userCurrency,
|
});
|
||||||
userId,
|
|
||||||
withExcludedAccounts
|
|
||||||
});
|
|
||||||
|
|
||||||
if (accountBalanceItems?.length <= 0 && activities?.length <= 0) {
|
if (accountBalanceItems?.length <= 0 && activities?.length <= 0) {
|
||||||
return {
|
return {
|
||||||
@ -1126,6 +1120,8 @@ export class PortfolioService {
|
|||||||
const { errors, hasErrors, historicalData } =
|
const { errors, hasErrors, historicalData } =
|
||||||
await portfolioCalculator.getSnapshot();
|
await portfolioCalculator.getSnapshot();
|
||||||
|
|
||||||
|
const { endDate, startDate } = getIntervalFromDateRange(dateRange);
|
||||||
|
|
||||||
const { chart } = await portfolioCalculator.getPerformance({
|
const { chart } = await portfolioCalculator.getPerformance({
|
||||||
end: endDate,
|
end: endDate,
|
||||||
start: startDate
|
start: startDate
|
||||||
@ -1175,10 +1171,11 @@ export class PortfolioService {
|
|||||||
const user = await this.userService.user({ id: userId });
|
const user = await this.userService.user({ id: userId });
|
||||||
const userCurrency = this.getUserCurrency(user);
|
const userCurrency = this.getUserCurrency(user);
|
||||||
|
|
||||||
const { activities } = await this.orderService.getOrders({
|
const { activities } =
|
||||||
userCurrency,
|
await this.orderService.getOrdersForPortfolioCalculator({
|
||||||
userId
|
userCurrency,
|
||||||
});
|
userId
|
||||||
|
});
|
||||||
|
|
||||||
const portfolioCalculator = this.calculatorFactory.createCalculator({
|
const portfolioCalculator = this.calculatorFactory.createCalculator({
|
||||||
activities,
|
activities,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user