Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
f46533107d | |||
c216ab1d76 | |||
86acbf06f4 | |||
3de7d3f60e | |||
63ed227f3f | |||
5bb20f6d5f | |||
b3e58d182a | |||
93d6746739 |
29
CHANGELOG.md
29
CHANGELOG.md
@ -5,6 +5,35 @@ 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/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 1.123.0 - 05.03.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Included data provider errors in the API response
|
||||
|
||||
### Changed
|
||||
|
||||
- Removed the redundant attributes (`currency`, `dataSource`, `symbol`) of the activity model
|
||||
- Removed the prefix for symbols with the data source `GHOSTFOLIO`
|
||||
|
||||
### Fixed
|
||||
|
||||
- Improved the account calculations
|
||||
|
||||
### Todo
|
||||
|
||||
- Apply data migration (`yarn database:migrate`)
|
||||
|
||||
## 1.122.0 - 01.03.2022
|
||||
|
||||
### Added
|
||||
|
||||
- Added support for click in the portfolio proportion chart component
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed an issue with undefined currencies after creating an activity
|
||||
|
||||
## 1.121.0 - 27.02.2022
|
||||
|
||||
### Added
|
||||
|
@ -101,16 +101,18 @@ export class AccountController {
|
||||
) {
|
||||
accountsWithAggregations = {
|
||||
...nullifyValuesInObject(accountsWithAggregations, [
|
||||
'totalBalance',
|
||||
'totalValue'
|
||||
'totalBalanceInBaseCurrency',
|
||||
'totalValueInBaseCurrency'
|
||||
]),
|
||||
accounts: nullifyValuesInObjects(accountsWithAggregations.accounts, [
|
||||
'balance',
|
||||
'balanceInBaseCurrency',
|
||||
'convertedBalance',
|
||||
'fee',
|
||||
'quantity',
|
||||
'unitPrice',
|
||||
'value'
|
||||
'value',
|
||||
'valueInBaseCurrency'
|
||||
])
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-
|
||||
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Account, Order, Platform, Prisma } from '@prisma/client';
|
||||
import Big from 'big.js';
|
||||
|
||||
import { CashDetails } from './interfaces/cash-details.interface';
|
||||
|
||||
@ -105,21 +106,26 @@ export class AccountService {
|
||||
aUserId: string,
|
||||
aCurrency: string
|
||||
): Promise<CashDetails> {
|
||||
let totalCashBalance = 0;
|
||||
let totalCashBalanceInBaseCurrency = new Big(0);
|
||||
|
||||
const accounts = await this.accounts({
|
||||
where: { userId: aUserId }
|
||||
});
|
||||
|
||||
accounts.forEach((account) => {
|
||||
totalCashBalance += this.exchangeRateDataService.toCurrency(
|
||||
account.balance,
|
||||
account.currency,
|
||||
aCurrency
|
||||
for (const account of accounts) {
|
||||
totalCashBalanceInBaseCurrency = totalCashBalanceInBaseCurrency.plus(
|
||||
this.exchangeRateDataService.toCurrency(
|
||||
account.balance,
|
||||
account.currency,
|
||||
aCurrency
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return { accounts, balance: totalCashBalance };
|
||||
return {
|
||||
accounts,
|
||||
balanceInBaseCurrency: totalCashBalanceInBaseCurrency.toNumber()
|
||||
};
|
||||
}
|
||||
|
||||
public async updateAccount(
|
||||
|
@ -2,5 +2,5 @@ import { Account } from '@prisma/client';
|
||||
|
||||
export interface CashDetails {
|
||||
accounts: Account[];
|
||||
balance: number;
|
||||
balanceInBaseCurrency: number;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ import {
|
||||
AdminData,
|
||||
AdminMarketData,
|
||||
AdminMarketDataDetails,
|
||||
AdminMarketDataItem
|
||||
AdminMarketDataItem,
|
||||
UniqueAsset
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource, Property } from '@prisma/client';
|
||||
@ -30,13 +31,7 @@ export class AdminService {
|
||||
private readonly symbolProfileService: SymbolProfileService
|
||||
) {}
|
||||
|
||||
public async deleteProfileData({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public async deleteProfileData({ dataSource, symbol }: UniqueAsset) {
|
||||
await this.marketDataService.deleteMany({ dataSource, symbol });
|
||||
await this.symbolProfileService.delete({ dataSource, symbol });
|
||||
}
|
||||
@ -137,10 +132,7 @@ export class AdminService {
|
||||
public async getMarketDataBySymbol({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}): Promise<AdminMarketDataDetails> {
|
||||
}: UniqueAsset): Promise<AdminMarketDataDetails> {
|
||||
return {
|
||||
marketData: await this.marketDataService.marketDataItems({
|
||||
orderBy: {
|
||||
|
@ -18,8 +18,6 @@ export class ExportService {
|
||||
orderBy: { date: 'desc' },
|
||||
select: {
|
||||
accountId: true,
|
||||
currency: true,
|
||||
dataSource: true,
|
||||
date: true,
|
||||
fee: true,
|
||||
id: true,
|
||||
@ -42,7 +40,6 @@ export class ExportService {
|
||||
orders: orders.map(
|
||||
({
|
||||
accountId,
|
||||
currency,
|
||||
date,
|
||||
fee,
|
||||
quantity,
|
||||
@ -52,12 +49,12 @@ export class ExportService {
|
||||
}) => {
|
||||
return {
|
||||
accountId,
|
||||
currency,
|
||||
date,
|
||||
fee,
|
||||
quantity,
|
||||
type,
|
||||
unitPrice,
|
||||
currency: SymbolProfile.currency,
|
||||
dataSource: SymbolProfile.dataSource,
|
||||
symbol: type === 'ITEM' ? SymbolProfile.name : SymbolProfile.symbol
|
||||
};
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
|
||||
import { Order } from '@prisma/client';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsArray, ValidateNested } from 'class-validator';
|
||||
|
||||
@ -7,5 +6,5 @@ export class ImportDataDto {
|
||||
@IsArray()
|
||||
@Type(() => CreateOrderDto)
|
||||
@ValidateNested({ each: true })
|
||||
orders: Order[];
|
||||
orders: CreateOrderDto[];
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ import { OrderService } from '@ghostfolio/api/app/order/order.service';
|
||||
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
|
||||
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Order } from '@prisma/client';
|
||||
import { isSameDay, parseISO } from 'date-fns';
|
||||
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ImportService {
|
||||
@ -19,7 +19,7 @@ export class ImportService {
|
||||
orders,
|
||||
userId
|
||||
}: {
|
||||
orders: Partial<Order>[];
|
||||
orders: Partial<CreateOrderDto>[];
|
||||
userId: string;
|
||||
}): Promise<void> {
|
||||
for (const order of orders) {
|
||||
@ -52,11 +52,8 @@ export class ImportService {
|
||||
unitPrice
|
||||
} of orders) {
|
||||
await this.orderService.createOrder({
|
||||
currency,
|
||||
dataSource,
|
||||
fee,
|
||||
quantity,
|
||||
symbol,
|
||||
type,
|
||||
unitPrice,
|
||||
userId,
|
||||
@ -65,6 +62,7 @@ export class ImportService {
|
||||
SymbolProfile: {
|
||||
connectOrCreate: {
|
||||
create: {
|
||||
currency,
|
||||
dataSource,
|
||||
symbol
|
||||
},
|
||||
@ -85,7 +83,7 @@ export class ImportService {
|
||||
orders,
|
||||
userId
|
||||
}: {
|
||||
orders: Partial<Order>[];
|
||||
orders: Partial<CreateOrderDto>[];
|
||||
userId: string;
|
||||
}) {
|
||||
if (
|
||||
@ -99,6 +97,7 @@ export class ImportService {
|
||||
}
|
||||
|
||||
const existingOrders = await this.orderService.orders({
|
||||
include: { SymbolProfile: true },
|
||||
orderBy: { date: 'desc' },
|
||||
where: { userId }
|
||||
});
|
||||
@ -109,12 +108,12 @@ export class ImportService {
|
||||
] of orders.entries()) {
|
||||
const duplicateOrder = existingOrders.find((order) => {
|
||||
return (
|
||||
order.currency === currency &&
|
||||
order.dataSource === dataSource &&
|
||||
order.SymbolProfile.currency === currency &&
|
||||
order.SymbolProfile.dataSource === dataSource &&
|
||||
isSameDay(order.date, parseISO(<string>(<unknown>date))) &&
|
||||
order.fee === fee &&
|
||||
order.quantity === quantity &&
|
||||
order.symbol === symbol &&
|
||||
order.SymbolProfile.symbol === symbol &&
|
||||
order.type === type &&
|
||||
order.unitPrice === unitPrice
|
||||
);
|
||||
|
@ -114,6 +114,7 @@ export class OrderController {
|
||||
SymbolProfile: {
|
||||
connectOrCreate: {
|
||||
create: {
|
||||
currency: data.currency,
|
||||
dataSource: data.dataSource,
|
||||
symbol: data.symbol
|
||||
},
|
||||
@ -171,6 +172,14 @@ export class OrderController {
|
||||
id_userId: { id: accountId, userId: this.request.user.id }
|
||||
}
|
||||
},
|
||||
SymbolProfile: {
|
||||
connect: {
|
||||
dataSource_symbol: {
|
||||
dataSource: data.dataSource,
|
||||
symbol: data.symbol
|
||||
}
|
||||
}
|
||||
},
|
||||
User: { connect: { id: this.request.user.id } }
|
||||
},
|
||||
where: {
|
||||
|
@ -53,7 +53,13 @@ export class OrderService {
|
||||
}
|
||||
|
||||
public async createOrder(
|
||||
data: Prisma.OrderCreateInput & { accountId?: string; userId: string }
|
||||
data: Prisma.OrderCreateInput & {
|
||||
accountId?: string;
|
||||
currency?: string;
|
||||
dataSource?: DataSource;
|
||||
symbol?: string;
|
||||
userId: string;
|
||||
}
|
||||
): Promise<Order> {
|
||||
const defaultAccount = (
|
||||
await this.accountService.getAccounts(data.userId)
|
||||
@ -71,15 +77,13 @@ export class OrderService {
|
||||
};
|
||||
|
||||
if (data.type === 'ITEM') {
|
||||
const currency = data.currency;
|
||||
const currency = data.SymbolProfile.connectOrCreate.create.currency;
|
||||
const dataSource: DataSource = 'MANUAL';
|
||||
const id = uuidv4();
|
||||
const name = data.SymbolProfile.connectOrCreate.create.symbol;
|
||||
|
||||
Account = undefined;
|
||||
data.dataSource = dataSource;
|
||||
data.id = id;
|
||||
data.symbol = null;
|
||||
data.SymbolProfile.connectOrCreate.create.currency = currency;
|
||||
data.SymbolProfile.connectOrCreate.create.dataSource = dataSource;
|
||||
data.SymbolProfile.connectOrCreate.create.name = name;
|
||||
@ -93,29 +97,32 @@ export class OrderService {
|
||||
data.SymbolProfile.connectOrCreate.create.symbol.toUpperCase();
|
||||
}
|
||||
|
||||
await this.dataGatheringService.gatherProfileData([
|
||||
{
|
||||
dataSource: data.SymbolProfile.connectOrCreate.create.dataSource,
|
||||
symbol: data.SymbolProfile.connectOrCreate.create.symbol
|
||||
}
|
||||
]);
|
||||
|
||||
const isDraft = isAfter(data.date as Date, endOfToday());
|
||||
|
||||
if (!isDraft) {
|
||||
// Gather symbol data of order in the background, if not draft
|
||||
this.dataGatheringService.gatherSymbols([
|
||||
{
|
||||
dataSource: data.dataSource,
|
||||
dataSource: data.SymbolProfile.connectOrCreate.create.dataSource,
|
||||
date: <Date>data.date,
|
||||
symbol: data.SymbolProfile.connectOrCreate.create.symbol
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
this.dataGatheringService.gatherProfileData([
|
||||
{
|
||||
dataSource: data.dataSource,
|
||||
symbol: data.SymbolProfile.connectOrCreate.create.symbol
|
||||
}
|
||||
]);
|
||||
|
||||
await this.cacheService.flush();
|
||||
|
||||
delete data.accountId;
|
||||
delete data.currency;
|
||||
delete data.dataSource;
|
||||
delete data.symbol;
|
||||
delete data.userId;
|
||||
|
||||
const orderData: Prisma.OrderCreateInput = data;
|
||||
@ -193,50 +200,60 @@ export class OrderService {
|
||||
value,
|
||||
feeInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
||||
order.fee,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
userCurrency
|
||||
),
|
||||
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
||||
value,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
userCurrency
|
||||
)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public async updateOrder(params: {
|
||||
public async updateOrder({
|
||||
data,
|
||||
where
|
||||
}: {
|
||||
data: Prisma.OrderUpdateInput & {
|
||||
currency?: string;
|
||||
dataSource?: DataSource;
|
||||
symbol?: string;
|
||||
};
|
||||
where: Prisma.OrderWhereUniqueInput;
|
||||
data: Prisma.OrderUpdateInput;
|
||||
}): Promise<Order> {
|
||||
const { data, where } = params;
|
||||
|
||||
if (data.Account.connect.id_userId.id === null) {
|
||||
delete data.Account;
|
||||
}
|
||||
|
||||
let isDraft = false;
|
||||
|
||||
if (data.type === 'ITEM') {
|
||||
const name = data.symbol;
|
||||
const name = data.SymbolProfile.connect.dataSource_symbol.symbol;
|
||||
|
||||
data.symbol = null;
|
||||
data.SymbolProfile = { update: { name } };
|
||||
}
|
||||
} else {
|
||||
isDraft = isAfter(data.date as Date, endOfToday());
|
||||
|
||||
const isDraft = isAfter(data.date as Date, endOfToday());
|
||||
|
||||
if (!isDraft) {
|
||||
// Gather symbol data of order in the background, if not draft
|
||||
this.dataGatheringService.gatherSymbols([
|
||||
{
|
||||
dataSource: <DataSource>data.dataSource,
|
||||
date: <Date>data.date,
|
||||
symbol: <string>data.symbol
|
||||
}
|
||||
]);
|
||||
if (!isDraft) {
|
||||
// Gather symbol data of order in the background, if not draft
|
||||
this.dataGatheringService.gatherSymbols([
|
||||
{
|
||||
dataSource: data.SymbolProfile.connect.dataSource_symbol.dataSource,
|
||||
date: <Date>data.date,
|
||||
symbol: data.SymbolProfile.connect.dataSource_symbol.symbol
|
||||
}
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
await this.cacheService.flush();
|
||||
|
||||
delete data.currency;
|
||||
delete data.dataSource;
|
||||
delete data.symbol;
|
||||
|
||||
return this.prismaService.order.update({
|
||||
data: {
|
||||
...data,
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { TimelinePosition } from '@ghostfolio/common/interfaces';
|
||||
import { ResponseError, TimelinePosition } from '@ghostfolio/common/interfaces';
|
||||
import Big from 'big.js';
|
||||
|
||||
export interface CurrentPositions {
|
||||
hasErrors: boolean;
|
||||
export interface CurrentPositions extends ResponseError {
|
||||
positions: TimelinePosition[];
|
||||
grossPerformance: Big;
|
||||
grossPerformancePercentage: Big;
|
||||
|
@ -66,6 +66,7 @@ describe('PortfolioCalculatorNew', () => {
|
||||
|
||||
expect(currentPositions).toEqual({
|
||||
currentValue: new Big('0'),
|
||||
errors: [],
|
||||
grossPerformance: new Big('-12.6'),
|
||||
grossPerformancePercentage: new Big('-0.0440867739678096571'),
|
||||
hasErrors: false,
|
||||
|
@ -55,6 +55,7 @@ describe('PortfolioCalculatorNew', () => {
|
||||
|
||||
expect(currentPositions).toEqual({
|
||||
currentValue: new Big('297.8'),
|
||||
errors: [],
|
||||
grossPerformance: new Big('24.6'),
|
||||
grossPerformancePercentage: new Big('0.09004392386530014641'),
|
||||
hasErrors: false,
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { TimelineInfoInterface } from '@ghostfolio/api/app/portfolio/interfaces/timeline-info.interface';
|
||||
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
|
||||
import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper';
|
||||
import { TimelinePosition } from '@ghostfolio/common/interfaces';
|
||||
import {
|
||||
ResponseError,
|
||||
TimelinePosition,
|
||||
UniqueAsset
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Type as TypeOfOrder } from '@prisma/client';
|
||||
import Big from 'big.js';
|
||||
@ -232,6 +236,8 @@ export class PortfolioCalculatorNew {
|
||||
const positions: TimelinePosition[] = [];
|
||||
let hasAnySymbolMetricsErrors = false;
|
||||
|
||||
const errors: ResponseError['errors'] = [];
|
||||
|
||||
for (const item of lastTransactionPoint.items) {
|
||||
const marketValue = marketSymbolMap[todayString]?.[item.symbol];
|
||||
|
||||
@ -272,12 +278,17 @@ export class PortfolioCalculatorNew {
|
||||
symbol: item.symbol,
|
||||
transactionCount: item.transactionCount
|
||||
});
|
||||
|
||||
if (hasErrors) {
|
||||
errors.push({ dataSource: item.dataSource, symbol: item.symbol });
|
||||
}
|
||||
}
|
||||
|
||||
const overall = this.calculateOverallPerformance(positions, initialValues);
|
||||
|
||||
return {
|
||||
...overall,
|
||||
errors,
|
||||
positions,
|
||||
hasErrors: hasAnySymbolMetricsErrors || overall.hasErrors
|
||||
};
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
PortfolioChart,
|
||||
PortfolioDetails,
|
||||
PortfolioInvestments,
|
||||
PortfolioPerformance,
|
||||
PortfolioPerformanceResponse,
|
||||
PortfolioPublicDetails,
|
||||
PortfolioReport,
|
||||
PortfolioSummary
|
||||
@ -204,10 +204,11 @@ export class PortfolioController {
|
||||
|
||||
@Get('performance')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@UseInterceptors(TransformDataSourceInResponseInterceptor)
|
||||
public async getPerformance(
|
||||
@Headers('impersonation-id') impersonationId: string,
|
||||
@Query('range') range
|
||||
): Promise<{ hasErrors: boolean; performance: PortfolioPerformance }> {
|
||||
): Promise<PortfolioPerformanceResponse> {
|
||||
const performanceInformation = await this.portfolioServiceStrategy
|
||||
.get()
|
||||
.getPerformance(impersonationId, range);
|
||||
|
@ -24,7 +24,7 @@ import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper';
|
||||
import {
|
||||
Accounts,
|
||||
PortfolioDetails,
|
||||
PortfolioPerformance,
|
||||
PortfolioPerformanceResponse,
|
||||
PortfolioReport,
|
||||
PortfolioSummary,
|
||||
Position,
|
||||
@ -100,15 +100,22 @@ export class PortfolioServiceNew {
|
||||
}
|
||||
}
|
||||
|
||||
const value = details.accounts[account.id]?.current ?? 0;
|
||||
|
||||
const result = {
|
||||
...account,
|
||||
transactionCount,
|
||||
convertedBalance: this.exchangeRateDataService.toCurrency(
|
||||
value,
|
||||
balanceInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
||||
account.balance,
|
||||
account.currency,
|
||||
userCurrency
|
||||
),
|
||||
value: details.accounts[account.id]?.current ?? 0
|
||||
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
||||
value,
|
||||
account.currency,
|
||||
userCurrency
|
||||
)
|
||||
};
|
||||
|
||||
delete result.Order;
|
||||
@ -119,17 +126,26 @@ export class PortfolioServiceNew {
|
||||
|
||||
public async getAccountsWithAggregations(aUserId: string): Promise<Accounts> {
|
||||
const accounts = await this.getAccounts(aUserId);
|
||||
let totalBalance = 0;
|
||||
let totalValue = 0;
|
||||
let totalBalanceInBaseCurrency = new Big(0);
|
||||
let totalValueInBaseCurrency = new Big(0);
|
||||
let transactionCount = 0;
|
||||
|
||||
for (const account of accounts) {
|
||||
totalBalance += account.convertedBalance;
|
||||
totalValue += account.value;
|
||||
totalBalanceInBaseCurrency = totalBalanceInBaseCurrency.plus(
|
||||
account.balanceInBaseCurrency
|
||||
);
|
||||
totalValueInBaseCurrency = totalValueInBaseCurrency.plus(
|
||||
account.valueInBaseCurrency
|
||||
);
|
||||
transactionCount += account.transactionCount;
|
||||
}
|
||||
|
||||
return { accounts, totalBalance, totalValue, transactionCount };
|
||||
return {
|
||||
accounts,
|
||||
transactionCount,
|
||||
totalBalanceInBaseCurrency: totalBalanceInBaseCurrency.toNumber(),
|
||||
totalValueInBaseCurrency: totalValueInBaseCurrency.toNumber()
|
||||
};
|
||||
}
|
||||
|
||||
public async getInvestments(
|
||||
@ -293,13 +309,11 @@ export class PortfolioServiceNew {
|
||||
orders: portfolioOrders
|
||||
});
|
||||
|
||||
if (transactionPoints?.length <= 0) {
|
||||
return { accounts: {}, holdings: {}, hasErrors: false };
|
||||
}
|
||||
|
||||
portfolioCalculator.setTransactionPoints(transactionPoints);
|
||||
|
||||
const portfolioStart = parseDate(transactionPoints[0].date);
|
||||
const portfolioStart = parseDate(
|
||||
transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT)
|
||||
);
|
||||
const startDate = this.getStartDate(aDateRange, portfolioStart);
|
||||
const currentPositions = await portfolioCalculator.getCurrentPositions(
|
||||
startDate
|
||||
@ -312,9 +326,11 @@ export class PortfolioServiceNew {
|
||||
|
||||
const holdings: PortfolioDetails['holdings'] = {};
|
||||
const totalInvestment = currentPositions.totalInvestment.plus(
|
||||
cashDetails.balance
|
||||
cashDetails.balanceInBaseCurrency
|
||||
);
|
||||
const totalValue = currentPositions.currentValue.plus(
|
||||
cashDetails.balanceInBaseCurrency
|
||||
);
|
||||
const totalValue = currentPositions.currentValue.plus(cashDetails.balance);
|
||||
|
||||
const dataGatheringItems = currentPositions.positions.map((position) => {
|
||||
return {
|
||||
@ -434,7 +450,7 @@ export class PortfolioServiceNew {
|
||||
};
|
||||
}
|
||||
|
||||
const positionCurrency = orders[0].currency;
|
||||
const positionCurrency = orders[0].SymbolProfile.currency;
|
||||
const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([
|
||||
aSymbol
|
||||
]);
|
||||
@ -444,13 +460,13 @@ export class PortfolioServiceNew {
|
||||
return order.type === 'BUY' || order.type === 'SELL';
|
||||
})
|
||||
.map((order) => ({
|
||||
currency: order.currency,
|
||||
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
|
||||
currency: order.SymbolProfile.currency,
|
||||
dataSource: order.SymbolProfile.dataSource,
|
||||
date: format(order.date, DATE_FORMAT),
|
||||
fee: new Big(order.fee),
|
||||
name: order.SymbolProfile?.name,
|
||||
quantity: new Big(order.quantity),
|
||||
symbol: order.symbol,
|
||||
symbol: order.SymbolProfile.symbol,
|
||||
type: order.type,
|
||||
unitPrice: new Big(order.unitPrice)
|
||||
}));
|
||||
@ -714,7 +730,7 @@ export class PortfolioServiceNew {
|
||||
public async getPerformance(
|
||||
aImpersonationId: string,
|
||||
aDateRange: DateRange = 'max'
|
||||
): Promise<{ hasErrors: boolean; performance: PortfolioPerformance }> {
|
||||
): Promise<PortfolioPerformanceResponse> {
|
||||
const userId = await this.getUserId(aImpersonationId, this.request.user.id);
|
||||
|
||||
const { portfolioOrders, transactionPoints } =
|
||||
@ -760,6 +776,7 @@ export class PortfolioServiceNew {
|
||||
currentPositions.netPerformancePercentage.toNumber();
|
||||
|
||||
return {
|
||||
errors: currentPositions.errors,
|
||||
hasErrors: currentPositions.hasErrors || hasErrors,
|
||||
performance: {
|
||||
currentGrossPerformance,
|
||||
@ -869,7 +886,7 @@ export class PortfolioServiceNew {
|
||||
|
||||
const performanceInformation = await this.getPerformance(aImpersonationId);
|
||||
|
||||
const { balance } = await this.accountService.getCashDetails(
|
||||
const { balanceInBaseCurrency } = await this.accountService.getCashDetails(
|
||||
userId,
|
||||
userCurrency
|
||||
);
|
||||
@ -887,7 +904,7 @@ export class PortfolioServiceNew {
|
||||
|
||||
const committedFunds = new Big(totalBuy).minus(totalSell);
|
||||
|
||||
const netWorth = new Big(balance)
|
||||
const netWorth = new Big(balanceInBaseCurrency)
|
||||
.plus(performanceInformation.performance.currentValue)
|
||||
.plus(items)
|
||||
.toNumber();
|
||||
@ -917,7 +934,7 @@ export class PortfolioServiceNew {
|
||||
netWorth,
|
||||
totalBuy,
|
||||
totalSell,
|
||||
cash: balance,
|
||||
cash: balanceInBaseCurrency,
|
||||
committedFunds: committedFunds.toNumber(),
|
||||
ordersCount: orders.filter((order) => {
|
||||
return order.type === 'BUY' || order.type === 'SELL';
|
||||
@ -1006,7 +1023,7 @@ export class PortfolioServiceNew {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
);
|
||||
})
|
||||
@ -1025,7 +1042,7 @@ export class PortfolioServiceNew {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
order.fee,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
);
|
||||
})
|
||||
@ -1047,7 +1064,7 @@ export class PortfolioServiceNew {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
);
|
||||
})
|
||||
@ -1100,24 +1117,24 @@ export class PortfolioServiceNew {
|
||||
}
|
||||
|
||||
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
|
||||
currency: order.currency,
|
||||
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
|
||||
currency: order.SymbolProfile.currency,
|
||||
dataSource: order.SymbolProfile.dataSource,
|
||||
date: format(order.date, DATE_FORMAT),
|
||||
fee: new Big(
|
||||
this.exchangeRateDataService.toCurrency(
|
||||
order.fee,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
userCurrency
|
||||
)
|
||||
),
|
||||
name: order.SymbolProfile?.name,
|
||||
quantity: new Big(order.quantity),
|
||||
symbol: order.symbol,
|
||||
symbol: order.SymbolProfile.symbol,
|
||||
type: order.type,
|
||||
unitPrice: new Big(
|
||||
this.exchangeRateDataService.toCurrency(
|
||||
order.unitPrice,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
userCurrency
|
||||
)
|
||||
)
|
||||
@ -1153,22 +1170,18 @@ export class PortfolioServiceNew {
|
||||
return accountId === account.id;
|
||||
});
|
||||
|
||||
const convertedBalance = this.exchangeRateDataService.toCurrency(
|
||||
account.balance,
|
||||
account.currency,
|
||||
userCurrency
|
||||
);
|
||||
accounts[account.id] = {
|
||||
balance: convertedBalance,
|
||||
balance: account.balance,
|
||||
currency: account.currency,
|
||||
current: convertedBalance,
|
||||
current: account.balance,
|
||||
name: account.name,
|
||||
original: convertedBalance
|
||||
original: account.balance
|
||||
};
|
||||
|
||||
for (const order of ordersByAccount) {
|
||||
let currentValueOfSymbol =
|
||||
order.quantity * portfolioItemsNow[order.symbol].marketPrice;
|
||||
order.quantity *
|
||||
portfolioItemsNow[order.SymbolProfile.symbol].marketPrice;
|
||||
let originalValueOfSymbol = order.quantity * order.unitPrice;
|
||||
|
||||
if (order.type === 'SELL') {
|
||||
@ -1218,7 +1231,7 @@ export class PortfolioServiceNew {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
order.quantity * order.unitPrice,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
currency
|
||||
);
|
||||
})
|
||||
|
@ -25,7 +25,7 @@ import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper';
|
||||
import {
|
||||
Accounts,
|
||||
PortfolioDetails,
|
||||
PortfolioPerformance,
|
||||
PortfolioPerformanceResponse,
|
||||
PortfolioReport,
|
||||
PortfolioSummary,
|
||||
Position,
|
||||
@ -99,15 +99,22 @@ export class PortfolioService {
|
||||
}
|
||||
}
|
||||
|
||||
const value = details.accounts[account.id]?.current ?? 0;
|
||||
|
||||
const result = {
|
||||
...account,
|
||||
transactionCount,
|
||||
convertedBalance: this.exchangeRateDataService.toCurrency(
|
||||
value,
|
||||
balanceInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
||||
account.balance,
|
||||
account.currency,
|
||||
userCurrency
|
||||
),
|
||||
value: details.accounts[account.id]?.current ?? 0
|
||||
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
|
||||
value,
|
||||
account.currency,
|
||||
userCurrency
|
||||
)
|
||||
};
|
||||
|
||||
delete result.Order;
|
||||
@ -118,17 +125,26 @@ export class PortfolioService {
|
||||
|
||||
public async getAccountsWithAggregations(aUserId: string): Promise<Accounts> {
|
||||
const accounts = await this.getAccounts(aUserId);
|
||||
let totalBalance = 0;
|
||||
let totalValue = 0;
|
||||
let totalBalanceInBaseCurrency = new Big(0);
|
||||
let totalValueInBaseCurrency = new Big(0);
|
||||
let transactionCount = 0;
|
||||
|
||||
for (const account of accounts) {
|
||||
totalBalance += account.convertedBalance;
|
||||
totalValue += account.value;
|
||||
totalBalanceInBaseCurrency = totalBalanceInBaseCurrency.plus(
|
||||
account.balanceInBaseCurrency
|
||||
);
|
||||
totalValueInBaseCurrency = totalValueInBaseCurrency.plus(
|
||||
account.valueInBaseCurrency
|
||||
);
|
||||
transactionCount += account.transactionCount;
|
||||
}
|
||||
|
||||
return { accounts, totalBalance, totalValue, transactionCount };
|
||||
return {
|
||||
accounts,
|
||||
transactionCount,
|
||||
totalBalanceInBaseCurrency: totalBalanceInBaseCurrency.toNumber(),
|
||||
totalValueInBaseCurrency: totalValueInBaseCurrency.toNumber()
|
||||
};
|
||||
}
|
||||
|
||||
public async getInvestments(
|
||||
@ -281,13 +297,11 @@ export class PortfolioService {
|
||||
userId
|
||||
});
|
||||
|
||||
if (transactionPoints?.length <= 0) {
|
||||
return { accounts: {}, holdings: {}, hasErrors: false };
|
||||
}
|
||||
|
||||
portfolioCalculator.setTransactionPoints(transactionPoints);
|
||||
|
||||
const portfolioStart = parseDate(transactionPoints[0].date);
|
||||
const portfolioStart = parseDate(
|
||||
transactionPoints[0]?.date ?? format(new Date(), DATE_FORMAT)
|
||||
);
|
||||
const startDate = this.getStartDate(aDateRange, portfolioStart);
|
||||
const currentPositions = await portfolioCalculator.getCurrentPositions(
|
||||
startDate
|
||||
@ -300,9 +314,11 @@ export class PortfolioService {
|
||||
|
||||
const holdings: PortfolioDetails['holdings'] = {};
|
||||
const totalInvestment = currentPositions.totalInvestment.plus(
|
||||
cashDetails.balance
|
||||
cashDetails.balanceInBaseCurrency
|
||||
);
|
||||
const totalValue = currentPositions.currentValue.plus(
|
||||
cashDetails.balanceInBaseCurrency
|
||||
);
|
||||
const totalValue = currentPositions.currentValue.plus(cashDetails.balance);
|
||||
|
||||
const dataGatheringItems = currentPositions.positions.map((position) => {
|
||||
return {
|
||||
@ -422,7 +438,7 @@ export class PortfolioService {
|
||||
};
|
||||
}
|
||||
|
||||
const positionCurrency = orders[0].currency;
|
||||
const positionCurrency = orders[0].SymbolProfile.currency;
|
||||
const [SymbolProfile] = await this.symbolProfileService.getSymbolProfiles([
|
||||
aSymbol
|
||||
]);
|
||||
@ -432,13 +448,13 @@ export class PortfolioService {
|
||||
return order.type === 'BUY' || order.type === 'SELL';
|
||||
})
|
||||
.map((order) => ({
|
||||
currency: order.currency,
|
||||
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
|
||||
currency: order.SymbolProfile.currency,
|
||||
dataSource: order.SymbolProfile.dataSource,
|
||||
date: format(order.date, DATE_FORMAT),
|
||||
fee: new Big(order.fee),
|
||||
name: order.SymbolProfile?.name,
|
||||
quantity: new Big(order.quantity),
|
||||
symbol: order.symbol,
|
||||
symbol: order.SymbolProfile.symbol,
|
||||
type: order.type,
|
||||
unitPrice: new Big(order.unitPrice)
|
||||
}));
|
||||
@ -696,7 +712,7 @@ export class PortfolioService {
|
||||
public async getPerformance(
|
||||
aImpersonationId: string,
|
||||
aDateRange: DateRange = 'max'
|
||||
): Promise<{ hasErrors: boolean; performance: PortfolioPerformance }> {
|
||||
): Promise<PortfolioPerformanceResponse> {
|
||||
const userId = await this.getUserId(aImpersonationId, this.request.user.id);
|
||||
|
||||
const portfolioCalculator = new PortfolioCalculator(
|
||||
@ -848,7 +864,7 @@ export class PortfolioService {
|
||||
|
||||
const performanceInformation = await this.getPerformance(aImpersonationId);
|
||||
|
||||
const { balance } = await this.accountService.getCashDetails(
|
||||
const { balanceInBaseCurrency } = await this.accountService.getCashDetails(
|
||||
userId,
|
||||
userCurrency
|
||||
);
|
||||
@ -866,7 +882,7 @@ export class PortfolioService {
|
||||
|
||||
const committedFunds = new Big(totalBuy).minus(totalSell);
|
||||
|
||||
const netWorth = new Big(balance)
|
||||
const netWorth = new Big(balanceInBaseCurrency)
|
||||
.plus(performanceInformation.performance.currentValue)
|
||||
.plus(items)
|
||||
.toNumber();
|
||||
@ -882,7 +898,7 @@ export class PortfolioService {
|
||||
totalSell,
|
||||
annualizedPerformancePercent:
|
||||
performanceInformation.performance.annualizedPerformancePercent,
|
||||
cash: balance,
|
||||
cash: balanceInBaseCurrency,
|
||||
committedFunds: committedFunds.toNumber(),
|
||||
ordersCount: orders.filter((order) => {
|
||||
return order.type === 'BUY' || order.type === 'SELL';
|
||||
@ -971,7 +987,7 @@ export class PortfolioService {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
);
|
||||
})
|
||||
@ -990,7 +1006,7 @@ export class PortfolioService {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
order.fee,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
);
|
||||
})
|
||||
@ -1012,7 +1028,7 @@ export class PortfolioService {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
new Big(order.quantity).mul(order.unitPrice).toNumber(),
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
this.request.user.Settings.currency
|
||||
);
|
||||
})
|
||||
@ -1064,24 +1080,24 @@ export class PortfolioService {
|
||||
}
|
||||
|
||||
const portfolioOrders: PortfolioOrder[] = orders.map((order) => ({
|
||||
currency: order.currency,
|
||||
dataSource: order.SymbolProfile?.dataSource ?? order.dataSource,
|
||||
currency: order.SymbolProfile.currency,
|
||||
dataSource: order.SymbolProfile.dataSource,
|
||||
date: format(order.date, DATE_FORMAT),
|
||||
fee: new Big(
|
||||
this.exchangeRateDataService.toCurrency(
|
||||
order.fee,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
userCurrency
|
||||
)
|
||||
),
|
||||
name: order.SymbolProfile?.name,
|
||||
quantity: new Big(order.quantity),
|
||||
symbol: order.symbol,
|
||||
symbol: order.SymbolProfile.symbol,
|
||||
type: order.type,
|
||||
unitPrice: new Big(
|
||||
this.exchangeRateDataService.toCurrency(
|
||||
order.unitPrice,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
userCurrency
|
||||
)
|
||||
)
|
||||
@ -1113,22 +1129,18 @@ export class PortfolioService {
|
||||
return accountId === account.id;
|
||||
});
|
||||
|
||||
const convertedBalance = this.exchangeRateDataService.toCurrency(
|
||||
account.balance,
|
||||
account.currency,
|
||||
userCurrency
|
||||
);
|
||||
accounts[account.id] = {
|
||||
balance: convertedBalance,
|
||||
balance: account.balance,
|
||||
currency: account.currency,
|
||||
current: convertedBalance,
|
||||
current: account.balance,
|
||||
name: account.name,
|
||||
original: convertedBalance
|
||||
original: account.balance
|
||||
};
|
||||
|
||||
for (const order of ordersByAccount) {
|
||||
let currentValueOfSymbol =
|
||||
order.quantity * portfolioItemsNow[order.symbol].marketPrice;
|
||||
order.quantity *
|
||||
portfolioItemsNow[order.SymbolProfile.symbol].marketPrice;
|
||||
let originalValueOfSymbol = order.quantity * order.unitPrice;
|
||||
|
||||
if (order.type === 'SELL') {
|
||||
@ -1178,7 +1190,7 @@ export class PortfolioService {
|
||||
.map((order) => {
|
||||
return this.exchangeRateDataService.toCurrency(
|
||||
order.quantity * order.unitPrice,
|
||||
order.currency,
|
||||
order.SymbolProfile.currency,
|
||||
currency
|
||||
);
|
||||
})
|
||||
|
@ -32,7 +32,6 @@ export class TransformDataSourceInResponseInterceptor<T>
|
||||
activity.SymbolProfile.dataSource = encodeDataSource(
|
||||
activity.SymbolProfile.dataSource
|
||||
);
|
||||
activity.dataSource = encodeDataSource(activity.dataSource);
|
||||
return activity;
|
||||
});
|
||||
}
|
||||
@ -41,6 +40,14 @@ export class TransformDataSourceInResponseInterceptor<T>
|
||||
data.dataSource = encodeDataSource(data.dataSource);
|
||||
}
|
||||
|
||||
if (data.errors) {
|
||||
for (const error of data.errors) {
|
||||
if (error.dataSource) {
|
||||
error.dataSource = encodeDataSource(error.dataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.holdings) {
|
||||
for (const symbol of Object.keys(data.holdings)) {
|
||||
if (data.holdings[symbol].dataSource) {
|
||||
@ -58,13 +65,6 @@ export class TransformDataSourceInResponseInterceptor<T>
|
||||
});
|
||||
}
|
||||
|
||||
if (data.orders) {
|
||||
data.orders.map((order) => {
|
||||
order.dataSource = encodeDataSource(order.dataSource);
|
||||
return order;
|
||||
});
|
||||
}
|
||||
|
||||
if (data.positions) {
|
||||
data.positions.map((position) => {
|
||||
position.dataSource = encodeDataSource(position.dataSource);
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
PROPERTY_LOCKED_DATA_GATHERING
|
||||
} from '@ghostfolio/common/config';
|
||||
import { DATE_FORMAT, resetHours } from '@ghostfolio/common/helper';
|
||||
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { DataSource } from '@prisma/client';
|
||||
import {
|
||||
@ -121,13 +122,7 @@ export class DataGatheringService {
|
||||
}
|
||||
}
|
||||
|
||||
public async gatherSymbol({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public async gatherSymbol({ dataSource, symbol }: UniqueAsset) {
|
||||
const isDataGatheringLocked = await this.prismaService.property.findUnique({
|
||||
where: { key: PROPERTY_LOCKED_DATA_GATHERING }
|
||||
});
|
||||
@ -554,19 +549,24 @@ export class DataGatheringService {
|
||||
}
|
||||
|
||||
private async getSymbolsProfileData(): Promise<IDataGatheringItem[]> {
|
||||
const distinctOrders = await this.prismaService.order.findMany({
|
||||
distinct: ['symbol'],
|
||||
orderBy: [{ symbol: 'asc' }],
|
||||
select: { dataSource: true, symbol: true }
|
||||
const symbolProfiles = await this.prismaService.symbolProfile.findMany({
|
||||
orderBy: [{ symbol: 'asc' }]
|
||||
});
|
||||
|
||||
return distinctOrders.filter((distinctOrder) => {
|
||||
return (
|
||||
distinctOrder.dataSource !== DataSource.GHOSTFOLIO &&
|
||||
distinctOrder.dataSource !== DataSource.MANUAL &&
|
||||
distinctOrder.dataSource !== DataSource.RAKUTEN
|
||||
);
|
||||
});
|
||||
return symbolProfiles
|
||||
.filter((symbolProfile) => {
|
||||
return (
|
||||
symbolProfile.dataSource !== DataSource.GHOSTFOLIO &&
|
||||
symbolProfile.dataSource !== DataSource.MANUAL &&
|
||||
symbolProfile.dataSource !== DataSource.RAKUTEN
|
||||
);
|
||||
})
|
||||
.map((symbolProfile) => {
|
||||
return {
|
||||
dataSource: symbolProfile.dataSource,
|
||||
symbol: symbolProfile.symbol
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private async isDataGatheringNeeded() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
||||
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
|
||||
import { DataProviderInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-provider.interface';
|
||||
import {
|
||||
IDataProviderHistoricalResponse,
|
||||
IDataProviderResponse
|
||||
@ -10,7 +11,6 @@ import { Injectable, Logger } from '@nestjs/common';
|
||||
import { DataSource, SymbolProfile } from '@prisma/client';
|
||||
import { isAfter, isBefore, parse } from 'date-fns';
|
||||
|
||||
import { DataProviderInterface } from '../interfaces/data-provider.interface';
|
||||
import { IAlphaVantageHistoricalResponse } from './interfaces/interfaces';
|
||||
|
||||
@Injectable()
|
||||
|
@ -7,11 +7,7 @@ import {
|
||||
} from '@ghostfolio/api/services/interfaces/interfaces';
|
||||
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
||||
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service';
|
||||
import {
|
||||
DATE_FORMAT,
|
||||
getYesterday,
|
||||
isGhostfolioScraperApiSymbol
|
||||
} from '@ghostfolio/common/helper';
|
||||
import { DATE_FORMAT, getYesterday } from '@ghostfolio/common/helper';
|
||||
import { Granularity } from '@ghostfolio/common/types';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { DataSource, SymbolProfile } from '@prisma/client';
|
||||
@ -29,7 +25,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
|
||||
) {}
|
||||
|
||||
public canHandle(symbol: string) {
|
||||
return isGhostfolioScraperApiSymbol(symbol);
|
||||
return true;
|
||||
}
|
||||
|
||||
public async getAssetProfile(
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
||||
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
|
||||
import { DataProviderInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-provider.interface';
|
||||
import {
|
||||
IDataProviderHistoricalResponse,
|
||||
IDataProviderResponse,
|
||||
@ -14,8 +15,6 @@ import { DataSource, SymbolProfile } from '@prisma/client';
|
||||
import * as bent from 'bent';
|
||||
import { format, subMonths, subWeeks, subYears } from 'date-fns';
|
||||
|
||||
import { DataProviderInterface } from '../interfaces/data-provider.interface';
|
||||
|
||||
@Injectable()
|
||||
export class RakutenRapidApiService implements DataProviderInterface {
|
||||
public static FEAR_AND_GREED_INDEX_NAME = 'Fear & Greed Index';
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface';
|
||||
import { CryptocurrencyService } from '@ghostfolio/api/services/cryptocurrency/cryptocurrency.service';
|
||||
import { DataProviderInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-provider.interface';
|
||||
import {
|
||||
IDataProviderHistoricalResponse,
|
||||
IDataProviderResponse,
|
||||
@ -19,9 +20,7 @@ import * as bent from 'bent';
|
||||
import Big from 'big.js';
|
||||
import { countries } from 'countries-list';
|
||||
import { addDays, format, isSameDay } from 'date-fns';
|
||||
import yahooFinance2 from 'yahoo-finance2';
|
||||
|
||||
import { DataProviderInterface } from '../interfaces/data-provider.interface';
|
||||
import yahooFinance from 'yahoo-finance2';
|
||||
|
||||
@Injectable()
|
||||
export class YahooFinanceService implements DataProviderInterface {
|
||||
@ -80,7 +79,7 @@ export class YahooFinanceService implements DataProviderInterface {
|
||||
|
||||
try {
|
||||
const symbol = this.convertToYahooFinanceSymbol(aSymbol);
|
||||
const assetProfile = await yahooFinance2.quoteSummary(symbol, {
|
||||
const assetProfile = await yahooFinance.quoteSummary(symbol, {
|
||||
modules: ['price', 'summaryProfile']
|
||||
});
|
||||
|
||||
@ -143,7 +142,7 @@ export class YahooFinanceService implements DataProviderInterface {
|
||||
const yahooFinanceSymbol = this.convertToYahooFinanceSymbol(aSymbol);
|
||||
|
||||
try {
|
||||
const historicalResult = await yahooFinance2.historical(
|
||||
const historicalResult = await yahooFinance.historical(
|
||||
yahooFinanceSymbol,
|
||||
{
|
||||
interval: '1d',
|
||||
@ -202,7 +201,7 @@ export class YahooFinanceService implements DataProviderInterface {
|
||||
try {
|
||||
const response: { [symbol: string]: IDataProviderResponse } = {};
|
||||
|
||||
const quotes = await yahooFinance2.quote(yahooFinanceSymbols);
|
||||
const quotes = await yahooFinance.quote(yahooFinanceSymbols);
|
||||
|
||||
for (const quote of quotes) {
|
||||
// Convert symbols back
|
||||
|
@ -114,6 +114,10 @@ export class ExchangeRateDataService {
|
||||
aFromCurrency: string,
|
||||
aToCurrency: string
|
||||
) {
|
||||
if (aValue === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const hasNaN = Object.values(this.exchangeRates).some((exchangeRate) => {
|
||||
return isNaN(exchangeRate);
|
||||
});
|
||||
@ -187,12 +191,7 @@ export class ExchangeRateDataService {
|
||||
await this.prismaService.symbolProfile.findMany({
|
||||
distinct: ['currency'],
|
||||
orderBy: [{ currency: 'asc' }],
|
||||
select: { currency: true },
|
||||
where: {
|
||||
currency: {
|
||||
not: null
|
||||
}
|
||||
}
|
||||
select: { currency: true }
|
||||
})
|
||||
).forEach((symbolProfile) => {
|
||||
currencies.push(symbolProfile.currency);
|
||||
@ -206,7 +205,7 @@ export class ExchangeRateDataService {
|
||||
currencies = currencies.concat(customCurrencies);
|
||||
}
|
||||
|
||||
return uniq(currencies).sort();
|
||||
return uniq(currencies).filter(Boolean).sort();
|
||||
}
|
||||
|
||||
private prepareCurrencyPairs(aCurrencies: string[]) {
|
||||
|
@ -2,6 +2,7 @@ import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-dat
|
||||
import { DateQuery } from '@ghostfolio/api/app/portfolio/interfaces/date-query.interface';
|
||||
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
||||
import { resetHours } from '@ghostfolio/common/helper';
|
||||
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource, MarketData, Prisma } from '@prisma/client';
|
||||
|
||||
@ -9,13 +10,7 @@ import { DataSource, MarketData, Prisma } from '@prisma/client';
|
||||
export class MarketDataService {
|
||||
public constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
public async deleteMany({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public async deleteMany({ dataSource, symbol }: UniqueAsset) {
|
||||
return this.prismaService.marketData.deleteMany({
|
||||
where: {
|
||||
dataSource,
|
||||
|
@ -86,7 +86,7 @@
|
||||
class="d-inline-block justify-content-end"
|
||||
[isCurrency]="true"
|
||||
[locale]="locale"
|
||||
[value]="element.convertedBalance"
|
||||
[value]="element.balance"
|
||||
></gf-value>
|
||||
</td>
|
||||
<td *matFooterCellDef class="px-1 text-right" mat-footer-cell>
|
||||
@ -94,7 +94,7 @@
|
||||
class="d-inline-block justify-content-end"
|
||||
[isCurrency]="true"
|
||||
[locale]="locale"
|
||||
[value]="totalBalance"
|
||||
[value]="totalBalanceInBaseCurrency"
|
||||
></gf-value>
|
||||
</td>
|
||||
</ng-container>
|
||||
@ -116,7 +116,7 @@
|
||||
class="d-inline-block justify-content-end"
|
||||
[isCurrency]="true"
|
||||
[locale]="locale"
|
||||
[value]="totalValue"
|
||||
[value]="totalValueInBaseCurrency"
|
||||
></gf-value>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
@ -24,8 +24,8 @@ export class AccountsTableComponent implements OnChanges, OnDestroy, OnInit {
|
||||
@Input() deviceType: string;
|
||||
@Input() locale: string;
|
||||
@Input() showActions: boolean;
|
||||
@Input() totalBalance: number;
|
||||
@Input() totalValue: number;
|
||||
@Input() totalBalanceInBaseCurrency: number;
|
||||
@Input() totalValueInBaseCurrency: number;
|
||||
@Input() transactionCount: number;
|
||||
|
||||
@Output() accountDeleted = new EventEmitter<string>();
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
import { AdminService } from '@ghostfolio/client/services/admin.service';
|
||||
import { DataService } from '@ghostfolio/client/services/data.service';
|
||||
import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config';
|
||||
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import { AdminMarketDataItem } from '@ghostfolio/common/interfaces/admin-market-data.interface';
|
||||
import { DataSource, MarketData } from '@prisma/client';
|
||||
import { Subject } from 'rxjs';
|
||||
@ -44,39 +45,21 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
|
||||
this.fetchAdminMarketData();
|
||||
}
|
||||
|
||||
public onDeleteProfileData({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public onDeleteProfileData({ dataSource, symbol }: UniqueAsset) {
|
||||
this.adminService
|
||||
.deleteProfileData({ dataSource, symbol })
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
.subscribe(() => {});
|
||||
}
|
||||
|
||||
public onGatherProfileDataBySymbol({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public onGatherProfileDataBySymbol({ dataSource, symbol }: UniqueAsset) {
|
||||
this.adminService
|
||||
.gatherProfileDataBySymbol({ dataSource, symbol })
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
.subscribe(() => {});
|
||||
}
|
||||
|
||||
public onGatherSymbol({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public onGatherSymbol({ dataSource, symbol }: UniqueAsset) {
|
||||
this.adminService
|
||||
.gatherSymbol({ dataSource, symbol })
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
@ -93,13 +76,7 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
public setCurrentProfile({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public setCurrentProfile({ dataSource, symbol }: UniqueAsset) {
|
||||
this.marketDataDetails = [];
|
||||
|
||||
if (this.currentSymbol === symbol) {
|
||||
@ -129,13 +106,7 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private fetchAdminMarketDataBySymbol({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
private fetchAdminMarketDataBySymbol({ dataSource, symbol }: UniqueAsset) {
|
||||
this.adminService
|
||||
.fetchAdminMarketDataBySymbol({ dataSource, symbol })
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
|
@ -7,7 +7,11 @@ import {
|
||||
} from '@ghostfolio/client/services/settings-storage.service';
|
||||
import { UserService } from '@ghostfolio/client/services/user/user.service';
|
||||
import { defaultDateRangeOptions } from '@ghostfolio/common/config';
|
||||
import { PortfolioPerformance, User } from '@ghostfolio/common/interfaces';
|
||||
import {
|
||||
PortfolioPerformance,
|
||||
UniqueAsset,
|
||||
User
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
||||
import { DateRange } from '@ghostfolio/common/types';
|
||||
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
|
||||
@ -24,6 +28,7 @@ export class HomeOverviewComponent implements OnDestroy, OnInit {
|
||||
public dateRange: DateRange;
|
||||
public dateRangeOptions = defaultDateRangeOptions;
|
||||
public deviceType: string;
|
||||
public errors: UniqueAsset[];
|
||||
public hasError: boolean;
|
||||
public hasImpersonationId: boolean;
|
||||
public hasPermissionToCreateOrder: boolean;
|
||||
@ -126,6 +131,7 @@ export class HomeOverviewComponent implements OnDestroy, OnInit {
|
||||
.fetchPortfolioPerformance({ range: this.dateRange })
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
.subscribe((response) => {
|
||||
this.errors = response.errors;
|
||||
this.hasError = response.hasErrors;
|
||||
this.performance = response.performance;
|
||||
this.isLoadingPerformance = false;
|
||||
|
@ -28,6 +28,7 @@
|
||||
class="pb-4"
|
||||
[baseCurrency]="user?.settings?.baseCurrency"
|
||||
[deviceType]="deviceType"
|
||||
[errors]="errors"
|
||||
[hasError]="hasError"
|
||||
[isAllTimeHigh]="isAllTimeHigh"
|
||||
[isAllTimeLow]="isAllTimeLow"
|
||||
|
@ -7,6 +7,7 @@
|
||||
? 'Sorry! Our data provider partner is experiencing the hiccups.'
|
||||
: ''
|
||||
"
|
||||
(click)="errors?.length > 0 && onShowErrors()"
|
||||
>
|
||||
<ion-icon
|
||||
*ngIf="hasError && !isLoading"
|
||||
|
@ -7,7 +7,10 @@ import {
|
||||
OnInit,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import { PortfolioPerformance } from '@ghostfolio/common/interfaces';
|
||||
import {
|
||||
PortfolioPerformance,
|
||||
ResponseError
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { CountUp } from 'countup.js';
|
||||
import { isNumber } from 'lodash';
|
||||
|
||||
@ -20,6 +23,7 @@ import { isNumber } from 'lodash';
|
||||
export class PortfolioPerformanceComponent implements OnChanges, OnInit {
|
||||
@Input() baseCurrency: string;
|
||||
@Input() deviceType: string;
|
||||
@Input() errors: ResponseError['errors'];
|
||||
@Input() hasError: boolean;
|
||||
@Input() isAllTimeHigh: boolean;
|
||||
@Input() isAllTimeLow: boolean;
|
||||
@ -69,4 +73,12 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onShowErrors() {
|
||||
const errorMessageParts = this.errors.map((error) => {
|
||||
return `${error.symbol} (${error.dataSource})`;
|
||||
});
|
||||
|
||||
alert(errorMessageParts.join('\n'));
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { Router } from '@angular/router';
|
||||
import { PortfolioPosition } from '@ghostfolio/common/interfaces';
|
||||
import { AssetClass, DataSource, Order as OrderModel } from '@prisma/client';
|
||||
import { PortfolioPosition, UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import { AssetClass, Order as OrderModel } from '@prisma/client';
|
||||
import { Subject, Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
@ -75,13 +75,7 @@ export class PositionsTableComponent implements OnChanges, OnDestroy, OnInit {
|
||||
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||
}*/
|
||||
|
||||
public onOpenPositionDialog({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}): void {
|
||||
public onOpenPositionDialog({ dataSource, symbol }: UniqueAsset): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { dataSource, symbol, positionDetailDialog: true }
|
||||
});
|
||||
|
@ -28,8 +28,8 @@ export class AccountsPageComponent implements OnDestroy, OnInit {
|
||||
public hasPermissionToCreateAccount: boolean;
|
||||
public hasPermissionToDeleteAccount: boolean;
|
||||
public routeQueryParams: Subscription;
|
||||
public totalBalance = 0;
|
||||
public totalValue = 0;
|
||||
public totalBalanceInBaseCurrency = 0;
|
||||
public totalValueInBaseCurrency = 0;
|
||||
public transactionCount = 0;
|
||||
public user: User;
|
||||
|
||||
@ -106,18 +106,25 @@ export class AccountsPageComponent implements OnDestroy, OnInit {
|
||||
this.dataService
|
||||
.fetchAccounts()
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
.subscribe(({ accounts, totalBalance, totalValue, transactionCount }) => {
|
||||
this.accounts = accounts;
|
||||
this.totalBalance = totalBalance;
|
||||
this.totalValue = totalValue;
|
||||
this.transactionCount = transactionCount;
|
||||
.subscribe(
|
||||
({
|
||||
accounts,
|
||||
totalBalanceInBaseCurrency,
|
||||
totalValueInBaseCurrency,
|
||||
transactionCount
|
||||
}) => {
|
||||
this.accounts = accounts;
|
||||
this.totalBalanceInBaseCurrency = totalBalanceInBaseCurrency;
|
||||
this.totalValueInBaseCurrency = totalValueInBaseCurrency;
|
||||
this.transactionCount = transactionCount;
|
||||
|
||||
if (this.accounts?.length <= 0) {
|
||||
this.router.navigate([], { queryParams: { createDialog: true } });
|
||||
if (this.accounts?.length <= 0) {
|
||||
this.router.navigate([], { queryParams: { createDialog: true } });
|
||||
}
|
||||
|
||||
this.changeDetectorRef.markForCheck();
|
||||
}
|
||||
|
||||
this.changeDetectorRef.markForCheck();
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
public onDeleteAccount(aId: string) {
|
||||
|
@ -9,8 +9,8 @@
|
||||
[deviceType]="deviceType"
|
||||
[locale]="user?.settings?.locale"
|
||||
[showActions]="!hasImpersonationId && hasPermissionToDeleteAccount && !user.settings.isRestrictedView"
|
||||
[totalBalance]="totalBalance"
|
||||
[totalValue]="totalValue"
|
||||
[totalBalanceInBaseCurrency]="totalBalanceInBaseCurrency"
|
||||
[totalValueInBaseCurrency]="totalValueInBaseCurrency"
|
||||
[transactionCount]="transactionCount"
|
||||
(accountDeleted)="onDeleteAccount($event)"
|
||||
(accountToUpdate)="onUpdateAccount($event)"
|
||||
|
@ -10,6 +10,7 @@ import { prettifySymbol } from '@ghostfolio/common/helper';
|
||||
import {
|
||||
PortfolioDetails,
|
||||
PortfolioPosition,
|
||||
UniqueAsset,
|
||||
User
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
|
||||
@ -64,7 +65,12 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
[name: string]: { name: string; value: number };
|
||||
};
|
||||
public symbols: {
|
||||
[name: string]: { name: string; symbol: string; value: number };
|
||||
[name: string]: {
|
||||
dataSource?: DataSource;
|
||||
name: string;
|
||||
symbol: string;
|
||||
value: number;
|
||||
};
|
||||
};
|
||||
|
||||
public user: User;
|
||||
@ -281,6 +287,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
|
||||
if (position.assetClass === AssetClass.EQUITY) {
|
||||
this.symbols[prettifySymbol(symbol)] = {
|
||||
dataSource: position.dataSource,
|
||||
name: position.name,
|
||||
symbol: prettifySymbol(symbol),
|
||||
value: aPeriod === 'original' ? position.investment : position.value
|
||||
@ -295,6 +302,14 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
|
||||
this.initializeAnalysisData(this.period);
|
||||
}
|
||||
|
||||
public onProportionChartClicked({ dataSource, symbol }: UniqueAsset) {
|
||||
if (dataSource && symbol) {
|
||||
this.router.navigate([], {
|
||||
queryParams: { dataSource, symbol, positionDetailDialog: true }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public ngOnDestroy() {
|
||||
this.unsubscribeSubject.next();
|
||||
this.unsubscribeSubject.complete();
|
||||
|
@ -89,12 +89,14 @@
|
||||
<mat-card-content>
|
||||
<gf-portfolio-proportion-chart
|
||||
class="mx-auto"
|
||||
cursor="pointer"
|
||||
[baseCurrency]="user?.settings?.baseCurrency"
|
||||
[isInPercent]="hasImpersonationId || user.settings.isRestrictedView"
|
||||
[keys]="['symbol']"
|
||||
[locale]="user?.settings?.locale"
|
||||
[positions]="symbols"
|
||||
[showLabels]="deviceType !== 'mobile'"
|
||||
(proportionChartClicked)="onProportionChartClicked($event)"
|
||||
></gf-portfolio-proportion-chart>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
@ -158,11 +158,11 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
||||
this.activityForm.controls['type'].disable();
|
||||
}
|
||||
|
||||
if (this.data.activity?.symbol) {
|
||||
if (this.data.activity?.SymbolProfile?.symbol) {
|
||||
this.dataService
|
||||
.fetchSymbolItem({
|
||||
dataSource: this.data.activity?.dataSource,
|
||||
symbol: this.data.activity?.symbol
|
||||
dataSource: this.data.activity?.SymbolProfile?.dataSource,
|
||||
symbol: this.data.activity?.SymbolProfile?.symbol
|
||||
})
|
||||
.pipe(takeUntil(this.unsubscribeSubject))
|
||||
.subscribe(({ marketPrice }) => {
|
||||
@ -196,9 +196,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
||||
} else {
|
||||
this.activityForm.controls['searchSymbol'].setErrors({ incorrect: true });
|
||||
|
||||
this.data.activity.currency = null;
|
||||
this.data.activity.dataSource = null;
|
||||
this.data.activity.symbol = null;
|
||||
this.data.activity.SymbolProfile = null;
|
||||
}
|
||||
|
||||
this.changeDetectorRef.markForCheck();
|
||||
@ -259,9 +257,7 @@ export class CreateOrUpdateTransactionDialog implements OnDestroy {
|
||||
})
|
||||
.pipe(
|
||||
catchError(() => {
|
||||
this.data.activity.currency = null;
|
||||
this.data.activity.dataSource = null;
|
||||
this.data.activity.unitPrice = null;
|
||||
this.data.activity.SymbolProfile = null;
|
||||
|
||||
this.isLoading = false;
|
||||
|
||||
|
@ -3,7 +3,10 @@ import { Injectable } from '@angular/core';
|
||||
import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-data.dto';
|
||||
import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces';
|
||||
import { DATE_FORMAT } from '@ghostfolio/common/helper';
|
||||
import { AdminMarketDataDetails } from '@ghostfolio/common/interfaces';
|
||||
import {
|
||||
AdminMarketDataDetails,
|
||||
UniqueAsset
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { DataSource, MarketData } from '@prisma/client';
|
||||
import { format, parseISO } from 'date-fns';
|
||||
import { Observable, map } from 'rxjs';
|
||||
@ -14,13 +17,7 @@ import { Observable, map } from 'rxjs';
|
||||
export class AdminService {
|
||||
public constructor(private http: HttpClient) {}
|
||||
|
||||
public deleteProfileData({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public deleteProfileData({ dataSource, symbol }: UniqueAsset) {
|
||||
return this.http.delete<void>(
|
||||
`/api/admin/profile-data/${dataSource}/${symbol}`
|
||||
);
|
||||
@ -53,13 +50,7 @@ export class AdminService {
|
||||
return this.http.post<void>(`/api/admin/gather/profile-data`, {});
|
||||
}
|
||||
|
||||
public gatherProfileDataBySymbol({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}) {
|
||||
public gatherProfileDataBySymbol({ dataSource, symbol }: UniqueAsset) {
|
||||
return this.http.post<void>(
|
||||
`/api/admin/gather/profile-data/${dataSource}/${symbol}`,
|
||||
{}
|
||||
@ -70,10 +61,8 @@ export class AdminService {
|
||||
dataSource,
|
||||
date,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
}: UniqueAsset & {
|
||||
date?: Date;
|
||||
symbol: string;
|
||||
}) {
|
||||
let url = `/api/admin/gather/${dataSource}/${symbol}`;
|
||||
|
||||
|
@ -24,9 +24,11 @@ import {
|
||||
PortfolioDetails,
|
||||
PortfolioInvestments,
|
||||
PortfolioPerformance,
|
||||
PortfolioPerformanceResponse,
|
||||
PortfolioPublicDetails,
|
||||
PortfolioReport,
|
||||
PortfolioSummary,
|
||||
UniqueAsset,
|
||||
User
|
||||
} from '@ghostfolio/common/interfaces';
|
||||
import { permissions } from '@ghostfolio/common/permissions';
|
||||
@ -188,13 +190,13 @@ export class DataService {
|
||||
});
|
||||
}
|
||||
|
||||
public fetchPortfolioPerformance(aParams: { [param: string]: any }) {
|
||||
return this.http.get<{
|
||||
hasErrors: boolean;
|
||||
performance: PortfolioPerformance;
|
||||
}>('/api/portfolio/performance', {
|
||||
params: aParams
|
||||
});
|
||||
public fetchPortfolioPerformance(params: { [param: string]: any }) {
|
||||
return this.http.get<PortfolioPerformanceResponse>(
|
||||
'/api/portfolio/performance',
|
||||
{
|
||||
params
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public fetchPortfolioPublic(aId: string) {
|
||||
|
@ -102,10 +102,6 @@ export function isCurrency(aSymbol = '') {
|
||||
return currencies[aSymbol];
|
||||
}
|
||||
|
||||
export function isGhostfolioScraperApiSymbol(aSymbol = '') {
|
||||
return aSymbol.startsWith(ghostfolioScraperApiSymbolPrefix);
|
||||
}
|
||||
|
||||
export function resetHours(aDate: Date) {
|
||||
const year = getYear(aDate);
|
||||
const month = getMonth(aDate);
|
||||
|
@ -2,7 +2,7 @@ import { AccountWithValue } from '@ghostfolio/common/types';
|
||||
|
||||
export interface Accounts {
|
||||
accounts: AccountWithValue[];
|
||||
totalBalance: number;
|
||||
totalValue: number;
|
||||
totalBalanceInBaseCurrency: number;
|
||||
totalValueInBaseCurrency: number;
|
||||
transactionCount: number;
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { Property } from '@prisma/client';
|
||||
|
||||
export interface AdminData {
|
||||
dataGatheringProgress?: number;
|
||||
exchangeRates: { label1: string; label2: string; value: number }[];
|
||||
|
@ -21,7 +21,10 @@ import { PortfolioReportRule } from './portfolio-report-rule.interface';
|
||||
import { PortfolioReport } from './portfolio-report.interface';
|
||||
import { PortfolioSummary } from './portfolio-summary.interface';
|
||||
import { Position } from './position.interface';
|
||||
import { ResponseError } from './responses/errors.interface';
|
||||
import { PortfolioPerformanceResponse } from './responses/portfolio-performance-response.interface';
|
||||
import { TimelinePosition } from './timeline-position.interface';
|
||||
import { UniqueAsset } from './unique-asset.interface';
|
||||
import { UserSettings } from './user-settings.interface';
|
||||
import { UserWithSettings } from './user-with-settings';
|
||||
import { User } from './user.interface';
|
||||
@ -42,13 +45,16 @@ export {
|
||||
PortfolioItem,
|
||||
PortfolioOverview,
|
||||
PortfolioPerformance,
|
||||
PortfolioPerformanceResponse,
|
||||
PortfolioPosition,
|
||||
PortfolioPublicDetails,
|
||||
PortfolioReport,
|
||||
PortfolioReportRule,
|
||||
PortfolioSummary,
|
||||
Position,
|
||||
ResponseError,
|
||||
TimelinePosition,
|
||||
UniqueAsset,
|
||||
User,
|
||||
UserSettings,
|
||||
UserWithSettings
|
||||
|
@ -0,0 +1,6 @@
|
||||
import { UniqueAsset } from '../unique-asset.interface';
|
||||
|
||||
export interface ResponseError {
|
||||
errors?: UniqueAsset[];
|
||||
hasErrors: boolean;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import { PortfolioPerformance } from '../portfolio-performance.interface';
|
||||
import { ResponseError } from './errors.interface';
|
||||
|
||||
export interface PortfolioPerformanceResponse extends ResponseError {
|
||||
performance: PortfolioPerformance;
|
||||
}
|
6
libs/common/src/lib/interfaces/unique-asset.interface.ts
Normal file
6
libs/common/src/lib/interfaces/unique-asset.interface.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { DataSource } from '@prisma/client';
|
||||
|
||||
export interface UniqueAsset {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
import { Account as AccountModel } from '@prisma/client';
|
||||
|
||||
export type AccountWithValue = AccountModel & {
|
||||
convertedBalance: number;
|
||||
balanceInBaseCurrency: number;
|
||||
transactionCount: number;
|
||||
value: number;
|
||||
valueInBaseCurrency: number;
|
||||
};
|
||||
|
@ -144,7 +144,7 @@
|
||||
class="d-none d-lg-table-cell px-1"
|
||||
mat-cell
|
||||
>
|
||||
{{ element.currency }}
|
||||
{{ element.SymbolProfile.currency }}
|
||||
</td>
|
||||
<td *matFooterCellDef class="d-none d-lg-table-cell px-1" mat-footer-cell>
|
||||
{{ baseCurrency }}
|
||||
@ -362,7 +362,7 @@
|
||||
!row.isDraft &&
|
||||
row.type !== 'ITEM' &&
|
||||
onOpenPositionDialog({
|
||||
dataSource: row.dataSource,
|
||||
dataSource: row.SymbolProfile.dataSource,
|
||||
symbol: row.SymbolProfile.symbol
|
||||
})
|
||||
"
|
||||
|
@ -21,6 +21,7 @@ import { MatTableDataSource } from '@angular/material/table';
|
||||
import { Router } from '@angular/router';
|
||||
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
|
||||
import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config';
|
||||
import { UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import { OrderWithAccount } from '@ghostfolio/common/types';
|
||||
import { DataSource } from '@prisma/client';
|
||||
import Big from 'big.js';
|
||||
@ -199,13 +200,7 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy {
|
||||
this.import.emit();
|
||||
}
|
||||
|
||||
public onOpenPositionDialog({
|
||||
dataSource,
|
||||
symbol
|
||||
}: {
|
||||
dataSource: DataSource;
|
||||
symbol: string;
|
||||
}): void {
|
||||
public onOpenPositionDialog({ dataSource, symbol }: UniqueAsset): void {
|
||||
this.router.navigate([], {
|
||||
queryParams: { dataSource, symbol, positionDetailDialog: true }
|
||||
});
|
||||
|
@ -3,14 +3,17 @@ import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
ElementRef,
|
||||
EventEmitter,
|
||||
Input,
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
Output,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import { UNKNOWN_KEY } from '@ghostfolio/common/config';
|
||||
import { getTextColor } from '@ghostfolio/common/helper';
|
||||
import { PortfolioPosition } from '@ghostfolio/common/interfaces';
|
||||
import { PortfolioPosition, UniqueAsset } from '@ghostfolio/common/interfaces';
|
||||
import { DataSource } from '@prisma/client';
|
||||
import Big from 'big.js';
|
||||
import { Tooltip } from 'chart.js';
|
||||
import { LinearScale } from 'chart.js';
|
||||
@ -30,6 +33,7 @@ export class PortfolioProportionChartComponent
|
||||
implements AfterViewInit, OnChanges, OnDestroy
|
||||
{
|
||||
@Input() baseCurrency: string;
|
||||
@Input() cursor: string;
|
||||
@Input() isInPercent = false;
|
||||
@Input() keys: string[] = [];
|
||||
@Input() locale = '';
|
||||
@ -37,11 +41,14 @@ export class PortfolioProportionChartComponent
|
||||
@Input() showLabels = false;
|
||||
@Input() positions: {
|
||||
[symbol: string]: Pick<PortfolioPosition, 'type'> & {
|
||||
dataSource?: DataSource;
|
||||
name: string;
|
||||
value: number;
|
||||
};
|
||||
} = {};
|
||||
|
||||
@Output() proportionChartClicked = new EventEmitter<UniqueAsset>();
|
||||
|
||||
@ViewChild('chartCanvas') chartCanvas: ElementRef<HTMLCanvasElement>;
|
||||
|
||||
public chart: Chart;
|
||||
@ -256,6 +263,21 @@ export class PortfolioProportionChartComponent
|
||||
layout: {
|
||||
padding: this.showLabels === true ? 100 : 0
|
||||
},
|
||||
onClick: (event, activeElements) => {
|
||||
const dataIndex = activeElements[0].index;
|
||||
const symbol: string = event.chart.data.labels[dataIndex];
|
||||
|
||||
const dataSource = this.positions[symbol]?.dataSource;
|
||||
|
||||
this.proportionChartClicked.emit({ dataSource, symbol });
|
||||
},
|
||||
onHover: (event, chartElement) => {
|
||||
if (this.cursor) {
|
||||
event.native.target.style.cursor = chartElement[0]
|
||||
? this.cursor
|
||||
: 'default';
|
||||
}
|
||||
},
|
||||
plugins: {
|
||||
datalabels: {
|
||||
color: (context) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ghostfolio",
|
||||
"version": "1.121.0",
|
||||
"version": "1.123.0",
|
||||
"homepage": "https://ghostfol.io",
|
||||
"license": "AGPL-3.0",
|
||||
"scripts": {
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Order" DROP COLUMN "dataSource";
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Order" DROP COLUMN "currency";
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Order" DROP COLUMN "symbol";
|
@ -0,0 +1,5 @@
|
||||
-- Set default value
|
||||
UPDATE "SymbolProfile" SET "currency" = 'USD' WHERE "currency" IS NULL;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "SymbolProfile" ALTER COLUMN "currency" SET NOT NULL;
|
@ -74,14 +74,11 @@ model Order {
|
||||
accountId String?
|
||||
accountUserId String?
|
||||
createdAt DateTime @default(now())
|
||||
currency String?
|
||||
dataSource DataSource?
|
||||
date DateTime
|
||||
fee Float
|
||||
id String @default(uuid())
|
||||
isDraft Boolean @default(false)
|
||||
quantity Float
|
||||
symbol String?
|
||||
SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
|
||||
symbolProfileId String
|
||||
type Type
|
||||
@ -119,7 +116,7 @@ model SymbolProfile {
|
||||
assetSubClass AssetSubClass?
|
||||
countries Json?
|
||||
createdAt DateTime @default(now())
|
||||
currency String?
|
||||
currency String
|
||||
dataSource DataSource
|
||||
id String @id @default(uuid())
|
||||
name String?
|
||||
|
@ -192,14 +192,11 @@ async function main() {
|
||||
{
|
||||
accountId: '65cfb79d-b6c7-4591-9d46-73426bc62094',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),
|
||||
fee: 30,
|
||||
id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',
|
||||
quantity: 50,
|
||||
symbol: 'TSLA',
|
||||
symbolProfileId: 'd1ee9681-fb21-4f99-a3b7-afd4fc04df2e',
|
||||
symbolProfileId: 'd1ee9681-fb21-4f99-a3b7-afd4fc04df2e', // TSLA
|
||||
type: Type.BUY,
|
||||
unitPrice: 42.97,
|
||||
userId: userDemo.id
|
||||
@ -207,14 +204,11 @@ async function main() {
|
||||
{
|
||||
accountId: 'd804de69-0429-42dc-b6ca-b308fd7dd926',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2017, 7, 16, 0, 0, 0)),
|
||||
fee: 29.9,
|
||||
id: 'a1c5d73a-8631-44e5-ac44-356827a5212c',
|
||||
quantity: 0.5614682,
|
||||
symbol: 'BTCUSD',
|
||||
symbolProfileId: 'fdc42ea6-1321-44f5-9fb0-d7f1f2cf9b1e',
|
||||
symbolProfileId: 'fdc42ea6-1321-44f5-9fb0-d7f1f2cf9b1e', // BTCUSD
|
||||
type: Type.BUY,
|
||||
unitPrice: 3562.089535970158,
|
||||
userId: userDemo.id
|
||||
@ -222,14 +216,11 @@ async function main() {
|
||||
{
|
||||
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2018, 9, 1, 0, 0, 0)),
|
||||
fee: 80.79,
|
||||
id: '71c08e2a-4a86-44ae-a890-c337de5d5f9b',
|
||||
quantity: 5,
|
||||
symbol: 'AMZN',
|
||||
symbolProfileId: '2bd26362-136e-411c-b578-334084b4cdcc',
|
||||
symbolProfileId: '2bd26362-136e-411c-b578-334084b4cdcc', // AMZN
|
||||
type: Type.BUY,
|
||||
unitPrice: 2021.99,
|
||||
userId: userDemo.id
|
||||
@ -237,14 +228,11 @@ async function main() {
|
||||
{
|
||||
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2019, 2, 1, 0, 0, 0)),
|
||||
fee: 19.9,
|
||||
id: '385f2c2c-d53e-4937-b0e5-e92ef6020d4e',
|
||||
quantity: 10,
|
||||
symbol: 'VTI',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796', // VTI
|
||||
type: Type.BUY,
|
||||
unitPrice: 144.38,
|
||||
userId: userDemo.id
|
||||
@ -252,14 +240,11 @@ async function main() {
|
||||
{
|
||||
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2019, 8, 3, 0, 0, 0)),
|
||||
fee: 19.9,
|
||||
id: '185f2c2c-d53e-4937-b0e5-a93ef6020d4e',
|
||||
quantity: 10,
|
||||
symbol: 'VTI',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796', // VTI
|
||||
type: Type.BUY,
|
||||
unitPrice: 147.99,
|
||||
userId: userDemo.id
|
||||
@ -267,14 +252,11 @@ async function main() {
|
||||
{
|
||||
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2020, 2, 2, 0, 0, 0)),
|
||||
fee: 19.9,
|
||||
id: '347b0430-a84f-4031-a0f9-390399066ad6',
|
||||
quantity: 10,
|
||||
symbol: 'VTI',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796', // VTI
|
||||
type: Type.BUY,
|
||||
unitPrice: 151.41,
|
||||
userId: userDemo.id
|
||||
@ -282,14 +264,11 @@ async function main() {
|
||||
{
|
||||
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2020, 8, 1, 0, 0, 0)),
|
||||
fee: 19.9,
|
||||
id: '67ec3f47-3189-4b63-ba05-60d3a06b302f',
|
||||
quantity: 10,
|
||||
symbol: 'VTI',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796', // VTI
|
||||
type: Type.BUY,
|
||||
unitPrice: 177.69,
|
||||
userId: userDemo.id
|
||||
@ -297,14 +276,11 @@ async function main() {
|
||||
{
|
||||
accountId: '480269ce-e12a-4fd1-ac88-c4b0ff3f899c',
|
||||
accountUserId: userDemo.id,
|
||||
currency: 'USD',
|
||||
dataSource: DataSource.YAHOO,
|
||||
date: new Date(Date.UTC(2020, 2, 1, 0, 0, 0)),
|
||||
fee: 19.9,
|
||||
id: 'd01c6fbc-fa8d-47e6-8e80-66f882d2bfd2',
|
||||
quantity: 10,
|
||||
symbol: 'VTI',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796',
|
||||
symbolProfileId: '7d9c8540-061e-4e7e-b019-0d0f4a84e796', // VTI
|
||||
type: Type.BUY,
|
||||
unitPrice: 203.15,
|
||||
userId: userDemo.id
|
||||
|
Reference in New Issue
Block a user