|
|
@ -2,7 +2,7 @@ import { CreateAccountBalanceDto } from '@ghostfolio/api/app/account-balance/cre
|
|
|
|
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
|
|
|
|
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
|
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
|
|
|
import { DataService } from '@ghostfolio/client/services/data.service';
|
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
|
|
|
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
|
|
|
import { downloadAsFile } from '@ghostfolio/common/helper';
|
|
|
|
import { DATE_FORMAT, downloadAsFile } from '@ghostfolio/common/helper';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
AccountBalancesResponse,
|
|
|
|
AccountBalancesResponse,
|
|
|
|
HistoricalDataItem,
|
|
|
|
HistoricalDataItem,
|
|
|
@ -27,7 +27,7 @@ import { Router } from '@angular/router';
|
|
|
|
import { Big } from 'big.js';
|
|
|
|
import { Big } from 'big.js';
|
|
|
|
import { format, parseISO } from 'date-fns';
|
|
|
|
import { format, parseISO } from 'date-fns';
|
|
|
|
import { isNumber } from 'lodash';
|
|
|
|
import { isNumber } from 'lodash';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { forkJoin, Subject } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
|
|
|
|
import { AccountDetailDialogParams } from './interfaces/interfaces';
|
|
|
|
import { AccountDetailDialogParams } from './interfaces/interfaces';
|
|
|
@ -87,11 +87,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
public ngOnInit() {
|
|
|
|
this.fetchAccount();
|
|
|
|
this.initialize();
|
|
|
|
this.fetchAccountBalances();
|
|
|
|
|
|
|
|
this.fetchActivities();
|
|
|
|
|
|
|
|
this.fetchPortfolioHoldings();
|
|
|
|
|
|
|
|
this.fetchPortfolioPerformance();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public onCloneActivity(aActivity: Activity) {
|
|
|
|
public onCloneActivity(aActivity: Activity) {
|
|
|
@ -111,9 +107,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
|
|
|
|
.postAccountBalance(accountBalance)
|
|
|
|
.postAccountBalance(accountBalance)
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.subscribe(() => {
|
|
|
|
.subscribe(() => {
|
|
|
|
this.fetchAccount();
|
|
|
|
this.initialize();
|
|
|
|
this.fetchAccountBalances();
|
|
|
|
|
|
|
|
this.fetchPortfolioPerformance();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -122,9 +116,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
|
|
|
|
.deleteAccountBalance(aId)
|
|
|
|
.deleteAccountBalance(aId)
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.subscribe(() => {
|
|
|
|
.subscribe(() => {
|
|
|
|
this.fetchAccount();
|
|
|
|
this.initialize();
|
|
|
|
this.fetchAccountBalances();
|
|
|
|
|
|
|
|
this.fetchPortfolioPerformance();
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -198,17 +190,6 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fetchAccountBalances() {
|
|
|
|
|
|
|
|
this.dataService
|
|
|
|
|
|
|
|
.fetchAccountBalances(this.data.accountId)
|
|
|
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
|
|
|
|
.subscribe(({ balances }) => {
|
|
|
|
|
|
|
|
this.accountBalances = balances;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fetchActivities() {
|
|
|
|
private fetchActivities() {
|
|
|
|
this.isLoadingActivities = true;
|
|
|
|
this.isLoadingActivities = true;
|
|
|
|
|
|
|
|
|
|
|
@ -229,28 +210,14 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fetchPortfolioHoldings() {
|
|
|
|
private fetchChart() {
|
|
|
|
this.dataService
|
|
|
|
|
|
|
|
.fetchPortfolioHoldings({
|
|
|
|
|
|
|
|
filters: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: 'ACCOUNT',
|
|
|
|
|
|
|
|
id: this.data.accountId
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
|
|
|
|
.subscribe(({ holdings }) => {
|
|
|
|
|
|
|
|
this.holdings = holdings;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fetchPortfolioPerformance() {
|
|
|
|
|
|
|
|
this.isLoadingChart = true;
|
|
|
|
this.isLoadingChart = true;
|
|
|
|
|
|
|
|
|
|
|
|
this.dataService
|
|
|
|
forkJoin({
|
|
|
|
|
|
|
|
accountBalances: this.dataService
|
|
|
|
|
|
|
|
.fetchAccountBalances(this.data.accountId)
|
|
|
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject)),
|
|
|
|
|
|
|
|
portfolioPerformance: this.dataService
|
|
|
|
.fetchPortfolioPerformance({
|
|
|
|
.fetchPortfolioPerformance({
|
|
|
|
filters: [
|
|
|
|
filters: [
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -263,22 +230,63 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
|
|
|
|
withItems: true
|
|
|
|
withItems: true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
.subscribe(({ chart }) => {
|
|
|
|
}).subscribe({
|
|
|
|
this.historicalDataItems = chart.map(
|
|
|
|
error: () => {
|
|
|
|
({ date, netWorth, netWorthInPercentage }) => {
|
|
|
|
this.isLoadingChart = false;
|
|
|
|
return {
|
|
|
|
},
|
|
|
|
|
|
|
|
next: ({ accountBalances, portfolioPerformance }) => {
|
|
|
|
|
|
|
|
this.accountBalances = accountBalances.balances;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (portfolioPerformance.chart.length > 0) {
|
|
|
|
|
|
|
|
this.historicalDataItems = portfolioPerformance.chart.map(
|
|
|
|
|
|
|
|
({ date, netWorth, netWorthInPercentage }) => ({
|
|
|
|
date,
|
|
|
|
date,
|
|
|
|
value: isNumber(netWorth) ? netWorth : netWorthInPercentage
|
|
|
|
value: isNumber(netWorth) ? netWorth : netWorthInPercentage
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.historicalDataItems = this.accountBalances.map(
|
|
|
|
|
|
|
|
({ date, valueInBaseCurrency }) => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
date: format(date, DATE_FORMAT),
|
|
|
|
|
|
|
|
value: valueInBaseCurrency
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.isLoadingChart = false;
|
|
|
|
this.isLoadingChart = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fetchPortfolioHoldings() {
|
|
|
|
|
|
|
|
this.dataService
|
|
|
|
|
|
|
|
.fetchPortfolioHoldings({
|
|
|
|
|
|
|
|
filters: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type: 'ACCOUNT',
|
|
|
|
|
|
|
|
id: this.data.accountId
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.pipe(takeUntil(this.unsubscribeSubject))
|
|
|
|
|
|
|
|
.subscribe(({ holdings }) => {
|
|
|
|
|
|
|
|
this.holdings = holdings;
|
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
this.changeDetectorRef.markForCheck();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private initialize() {
|
|
|
|
|
|
|
|
this.fetchAccount();
|
|
|
|
|
|
|
|
this.fetchActivities();
|
|
|
|
|
|
|
|
this.fetchChart();
|
|
|
|
|
|
|
|
this.fetchPortfolioHoldings();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
public ngOnDestroy() {
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.next();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|
this.unsubscribeSubject.complete();
|
|
|
|