Compare commits

..

16 Commits

Author SHA1 Message Date
48f6b8d353 Release 1.111.0 (#671) 2022-02-03 21:00:53 +01:00
f369996912 Bugfix/fix symbol selection of 7d data gathering (#670)
* Fix symbol selection of 7d data gathering

* Update changelog
2022-02-03 20:58:59 +01:00
dc424a86ec Feature/support deleting symbol profile data (#669)
* Add support for deleting symbol profile data

* Update changelog
2022-02-03 20:56:39 +01:00
5d8bde5a70 Feature/access data source and symbol from symbol profile (#668)
* Access dataSource and symbol from SymbolProfile

* Update changelog
2022-02-03 19:21:55 +01:00
16360c0c67 Feature/minor code cleanup (#667)
* Sort imports

* Update changelog
2022-02-02 22:06:34 +01:00
526a6b2030 Release 1.110.0 (#665) 2022-02-02 20:31:23 +01:00
5000e9c79b Feature/update database schema of order (#664)
* Add schema migrations

* Update changelog
2022-02-02 20:29:19 +01:00
161cb82820 Bugfix/fix data source of fear and greed index (#663)
* Encode data source

* Update changelog
2022-02-02 20:07:33 +01:00
fed28f29d1 Release 1.109.0 (#662) 2022-02-01 21:05:14 +01:00
8bd9330acc Feature/improve usability of create or edit transaction dialog (#661)
* Move the fee to the bottom

* Update changelog
2022-02-01 20:35:44 +01:00
155c08d665 Transform data source (#658)
* Transform data source

* Update changelog
2022-02-01 20:35:25 +01:00
b8ad6d6662 Feature/improve import (#657)
* Improve import

* Update changelog

Co-Authored-By: Ronald Konjer <ronaldkonjer@gmail.com>
2022-02-01 19:12:00 +01:00
9d6977e3f7 Feature/support cryptocurrency mina protocol (#659)
* Support Mina Protocol (MINA-USD)

* Update changelog
2022-02-01 10:58:34 +01:00
919b20197f import csv with account name or id (#654)
* import csv with account id
2022-01-29 17:27:33 +01:00
62885ea890 Feature/improve consistent use of symbol with data source (#656)
* Improve the consistent use of symbol with dataSource

* Update changelog
2022-01-29 16:51:37 +01:00
035d8ad9eb Update copyright (#655) 2022-01-29 09:15:11 +01:00
54 changed files with 704 additions and 404 deletions

View File

@ -5,6 +5,49 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.111.0 - 03.02.2022
### Added
- Added support for deleting symbol profile data in the admin control panel
### Changed
- Used `dataSource` and `symbol` from `SymbolProfile` instead of the `order` object (in `ExportService` and `PortfolioService`)
### Fixed
- Fixed the symbol selection of the 7d data gathering
## 1.110.0 - 02.02.2022
### Fixed
- Fixed the data source of the _Fear & Greed Index_ (market mood)
### Todo
- Apply data migration (`yarn database:migrate`)
## 1.109.0 - 01.02.2022
### Added
- Added support for the (optional) `accountId` in the import functionality for activities
- Added support for the (optional) `dataSource` in the import functionality for activities
- Added support for the data source transformation
- Added support for the cryptocurrency _Mina Protocol_ (`MINA-USD`)
### Changed
- Improved the usability of the form in the create or edit transaction dialog
- Improved the consistent use of `symbol` in combination with `dataSource`
- Removed the primary data source from the client
### Removed
- Removed the unused endpoint `GET api/order/:id`
## 1.108.0 - 27.01.2022 ## 1.108.0 - 27.01.2022
### Changed ### Changed
@ -200,7 +243,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Added support for cryptocurrency _Solana_ (`SOL-USD`) - Added support for the cryptocurrency _Solana_ (`SOL-USD`)
- Extended the documentation for self-hosting with the [official Ghostfolio Docker image](https://hub.docker.com/r/ghostfolio/ghostfolio) - Extended the documentation for self-hosting with the [official Ghostfolio Docker image](https://hub.docker.com/r/ghostfolio/ghostfolio)
### Fixed ### Fixed

View File

@ -187,6 +187,6 @@ Not sure what to work on? We have got some ideas. Please join the Ghostfolio [Sl
## License ## License
© 2021 [Ghostfolio](https://ghostfol.io) © 2022 [Ghostfolio](https://ghostfol.io)
Licensed under the [AGPLv3 License](https://www.gnu.org/licenses/agpl-3.0.html). Licensed under the [AGPLv3 License](https://www.gnu.org/licenses/agpl-3.0.html).

View File

@ -11,6 +11,7 @@ import type { RequestWithUser } from '@ghostfolio/common/types';
import { import {
Body, Body,
Controller, Controller,
Delete,
Get, Get,
HttpException, HttpException,
Inject, Inject,
@ -195,9 +196,10 @@ export class AdminController {
return this.adminService.getMarketData(); return this.adminService.getMarketData();
} }
@Get('market-data/:symbol') @Get('market-data/:dataSource/:symbol')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async getMarketDataBySymbol( public async getMarketDataBySymbol(
@Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string @Param('symbol') symbol: string
): Promise<AdminMarketDataDetails> { ): Promise<AdminMarketDataDetails> {
if ( if (
@ -212,7 +214,7 @@ export class AdminController {
); );
} }
return this.adminService.getMarketDataBySymbol(symbol); return this.adminService.getMarketDataBySymbol({ dataSource, symbol });
} }
@Put('market-data/:dataSource/:symbol/:dateString') @Put('market-data/:dataSource/:symbol/:dateString')
@ -248,6 +250,27 @@ export class AdminController {
}); });
} }
@Delete('profile-data/:dataSource/:symbol')
@UseGuards(AuthGuard('jwt'))
public async deleteProfileData(
@Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string
): Promise<void> {
if (
!hasPermission(
this.request.user.permissions,
permissions.accessAdminControl
)
) {
throw new HttpException(
getReasonPhrase(StatusCodes.FORBIDDEN),
StatusCodes.FORBIDDEN
);
}
return this.adminService.deleteProfileData({ dataSource, symbol });
}
@Put('settings/:key') @Put('settings/:key')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async updateProperty( public async updateProperty(

View File

@ -6,6 +6,7 @@ import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-d
import { MarketDataModule } from '@ghostfolio/api/services/market-data.module'; import { MarketDataModule } from '@ghostfolio/api/services/market-data.module';
import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { PrismaModule } from '@ghostfolio/api/services/prisma.module';
import { PropertyModule } from '@ghostfolio/api/services/property/property.module'; import { PropertyModule } from '@ghostfolio/api/services/property/property.module';
import { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile.module';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { AdminController } from './admin.controller'; import { AdminController } from './admin.controller';
@ -20,7 +21,8 @@ import { AdminService } from './admin.service';
MarketDataModule, MarketDataModule,
PrismaModule, PrismaModule,
PropertyModule, PropertyModule,
SubscriptionModule SubscriptionModule,
SymbolProfileModule
], ],
controllers: [AdminController], controllers: [AdminController],
providers: [AdminService], providers: [AdminService],

View File

@ -5,6 +5,7 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-
import { MarketDataService } from '@ghostfolio/api/services/market-data.service'; import { MarketDataService } from '@ghostfolio/api/services/market-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { PropertyService } from '@ghostfolio/api/services/property/property.service';
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service';
import { PROPERTY_CURRENCIES, baseCurrency } from '@ghostfolio/common/config'; import { PROPERTY_CURRENCIES, baseCurrency } from '@ghostfolio/common/config';
import { import {
AdminData, AdminData,
@ -13,7 +14,7 @@ import {
AdminMarketDataItem AdminMarketDataItem
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Property } from '@prisma/client'; import { DataSource, Property } from '@prisma/client';
import { differenceInDays } from 'date-fns'; import { differenceInDays } from 'date-fns';
@Injectable() @Injectable()
@ -25,9 +26,21 @@ export class AdminService {
private readonly marketDataService: MarketDataService, private readonly marketDataService: MarketDataService,
private readonly prismaService: PrismaService, private readonly prismaService: PrismaService,
private readonly propertyService: PropertyService, private readonly propertyService: PropertyService,
private readonly subscriptionService: SubscriptionService private readonly subscriptionService: SubscriptionService,
private readonly symbolProfileService: SymbolProfileService
) {} ) {}
public async deleteProfileData({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
await this.marketDataService.deleteMany({ dataSource, symbol });
await this.symbolProfileService.delete({ dataSource, symbol });
}
public async get(): Promise<AdminData> { public async get(): Promise<AdminData> {
return { return {
dataGatheringProgress: dataGatheringProgress:
@ -121,16 +134,21 @@ export class AdminService {
}; };
} }
public async getMarketDataBySymbol( public async getMarketDataBySymbol({
aSymbol: string dataSource,
): Promise<AdminMarketDataDetails> { symbol
}: {
dataSource: DataSource;
symbol: string;
}): Promise<AdminMarketDataDetails> {
return { return {
marketData: await this.marketDataService.marketDataItems({ marketData: await this.marketDataService.marketDataItems({
orderBy: { orderBy: {
date: 'asc' date: 'asc'
}, },
where: { where: {
symbol: aSymbol dataSource,
symbol
} }
}) })
}; };

View File

@ -11,12 +11,13 @@ export class ExportService {
const orders = await this.prismaService.order.findMany({ const orders = await this.prismaService.order.findMany({
orderBy: { date: 'desc' }, orderBy: { date: 'desc' },
select: { select: {
accountId: true,
currency: true, currency: true,
dataSource: true, dataSource: true,
date: true, date: true,
fee: true, fee: true,
quantity: true, quantity: true,
symbol: true, SymbolProfile: true,
type: true, type: true,
unitPrice: true unitPrice: true
}, },
@ -25,7 +26,30 @@ export class ExportService {
return { return {
meta: { date: new Date().toISOString(), version: environment.version }, meta: { date: new Date().toISOString(), version: environment.version },
orders orders: orders.map(
({
accountId,
currency,
date,
fee,
quantity,
SymbolProfile,
type,
unitPrice
}) => {
return {
accountId,
currency,
date,
fee,
quantity,
type,
unitPrice,
dataSource: SymbolProfile.dataSource,
symbol: SymbolProfile.symbol
};
}
)
}; };
} }
} }

View File

@ -20,6 +20,11 @@ export class ImportService {
orders: Partial<Order>[]; orders: Partial<Order>[];
userId: string; userId: string;
}): Promise<void> { }): Promise<void> {
for (const order of orders) {
order.dataSource =
order.dataSource ?? this.dataProviderService.getPrimaryDataSource();
}
await this.validateOrders({ orders, userId }); await this.validateOrders({ orders, userId });
for (const { for (const {
@ -34,6 +39,7 @@ export class ImportService {
unitPrice unitPrice
} of orders) { } of orders) {
await this.orderService.createOrder({ await this.orderService.createOrder({
accountId,
currency, currency,
dataSource, dataSource,
fee, fee,
@ -41,11 +47,7 @@ export class ImportService {
symbol, symbol,
type, type,
unitPrice, unitPrice,
Account: { userId,
connect: {
id_userId: { userId, id: accountId }
}
},
date: parseISO(<string>(<unknown>date)), date: parseISO(<string>(<unknown>date)),
SymbolProfile: { SymbolProfile: {
connectOrCreate: { connectOrCreate: {

View File

@ -1,7 +1,6 @@
import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service';
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service';
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { PropertyService } from '@ghostfolio/api/services/property/property.service';
@ -12,12 +11,14 @@ import {
PROPERTY_STRIPE_CONFIG, PROPERTY_STRIPE_CONFIG,
PROPERTY_SYSTEM_MESSAGE PROPERTY_SYSTEM_MESSAGE
} from '@ghostfolio/common/config'; } from '@ghostfolio/common/config';
import { encodeDataSource } from '@ghostfolio/common/helper';
import { InfoItem } from '@ghostfolio/common/interfaces'; import { InfoItem } from '@ghostfolio/common/interfaces';
import { Statistics } from '@ghostfolio/common/interfaces/statistics.interface'; import { Statistics } from '@ghostfolio/common/interfaces/statistics.interface';
import { Subscription } from '@ghostfolio/common/interfaces/subscription.interface'; import { Subscription } from '@ghostfolio/common/interfaces/subscription.interface';
import { permissions } from '@ghostfolio/common/permissions'; import { permissions } from '@ghostfolio/common/permissions';
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt'; import { JwtService } from '@nestjs/jwt';
import { DataSource } from '@prisma/client';
import * as bent from 'bent'; import * as bent from 'bent';
import { subDays } from 'date-fns'; import { subDays } from 'date-fns';
@ -27,7 +28,6 @@ export class InfoService {
public constructor( public constructor(
private readonly configurationService: ConfigurationService, private readonly configurationService: ConfigurationService,
private readonly dataProviderService: DataProviderService,
private readonly exchangeRateDataService: ExchangeRateDataService, private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly dataGatheringService: DataGatheringService, private readonly dataGatheringService: DataGatheringService,
private readonly jwtService: JwtService, private readonly jwtService: JwtService,
@ -51,6 +51,10 @@ export class InfoService {
globalPermissions.push(permissions.enableBlog); globalPermissions.push(permissions.enableBlog);
} }
if (this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX')) {
info.fearAndGreedDataSource = encodeDataSource(DataSource.RAKUTEN);
}
if (this.configurationService.get('ENABLE_FEATURE_IMPORT')) { if (this.configurationService.get('ENABLE_FEATURE_IMPORT')) {
globalPermissions.push(permissions.enableImport); globalPermissions.push(permissions.enableImport);
} }
@ -92,7 +96,6 @@ export class InfoService {
currencies: this.exchangeRateDataService.getCurrencies(), currencies: this.exchangeRateDataService.getCurrencies(),
demoAuthToken: this.getDemoAuthToken(), demoAuthToken: this.getDemoAuthToken(),
lastDataGathering: await this.getLastDataGathering(), lastDataGathering: await this.getLastDataGathering(),
primaryDataSource: this.dataProviderService.getPrimaryDataSource(),
statistics: await this.getStatistics(), statistics: await this.getStatistics(),
subscriptions: await this.getSubscriptions() subscriptions: await this.getSubscriptions()
}; };

View File

@ -1,14 +1,22 @@
import { DataSource, Type } from '@prisma/client'; import { DataSource, Type } from '@prisma/client';
import { IsEnum, IsISO8601, IsNumber, IsString } from 'class-validator'; import {
IsEnum,
IsISO8601,
IsNumber,
IsOptional,
IsString
} from 'class-validator';
export class CreateOrderDto { export class CreateOrderDto {
@IsString() @IsString()
@IsOptional()
accountId: string; accountId: string;
@IsString() @IsString()
currency: string; currency: string;
@IsEnum(DataSource, { each: true }) @IsEnum(DataSource, { each: true })
@IsOptional()
dataSource: DataSource; dataSource: DataSource;
@IsISO8601() @IsISO8601()

View File

@ -1,5 +1,7 @@
import { UserService } from '@ghostfolio/api/app/user/user.service'; import { UserService } from '@ghostfolio/api/app/user/user.service';
import { nullifyValuesInObjects } from '@ghostfolio/api/helper/object.helper'; import { nullifyValuesInObjects } from '@ghostfolio/api/helper/object.helper';
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor';
import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response.interceptor';
import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service'; import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service';
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import type { RequestWithUser } from '@ghostfolio/common/types'; import type { RequestWithUser } from '@ghostfolio/common/types';
@ -14,7 +16,8 @@ import {
Param, Param,
Post, Post,
Put, Put,
UseGuards UseGuards,
UseInterceptors
} from '@nestjs/common'; } from '@nestjs/common';
import { REQUEST } from '@nestjs/core'; import { REQUEST } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
@ -58,6 +61,7 @@ export class OrderController {
@Get() @Get()
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInResponseInterceptor)
public async getAllOrders( public async getAllOrders(
@Headers('impersonation-id') impersonationId @Headers('impersonation-id') impersonationId
): Promise<Activities> { ): Promise<Activities> {
@ -91,19 +95,9 @@ export class OrderController {
return { activities }; return { activities };
} }
@Get(':id')
@UseGuards(AuthGuard('jwt'))
public async getOrderById(@Param('id') id: string): Promise<OrderModel> {
return this.orderService.order({
id_userId: {
id,
userId: this.request.user.id
}
});
}
@Post() @Post()
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInRequestInterceptor)
public async createOrder(@Body() data: CreateOrderDto): Promise<OrderModel> { public async createOrder(@Body() data: CreateOrderDto): Promise<OrderModel> {
if ( if (
!hasPermission(this.request.user.permissions, permissions.createOrder) !hasPermission(this.request.user.permissions, permissions.createOrder)
@ -114,19 +108,9 @@ export class OrderController {
); );
} }
const date = parseISO(data.date);
const accountId = data.accountId;
delete data.accountId;
return this.orderService.createOrder({ return this.orderService.createOrder({
...data, ...data,
date, date: parseISO(data.date),
Account: {
connect: {
id_userId: { id: accountId, userId: this.request.user.id }
}
},
SymbolProfile: { SymbolProfile: {
connectOrCreate: { connectOrCreate: {
create: { create: {
@ -141,12 +125,14 @@ export class OrderController {
} }
} }
}, },
User: { connect: { id: this.request.user.id } } User: { connect: { id: this.request.user.id } },
userId: this.request.user.id
}); });
} }
@Put(':id') @Put(':id')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInRequestInterceptor)
public async update(@Param('id') id: string, @Body() data: UpdateOrderDto) { public async update(@Param('id') id: string, @Body() data: UpdateOrderDto) {
if ( if (
!hasPermission(this.request.user.permissions, permissions.updateOrder) !hasPermission(this.request.user.permissions, permissions.updateOrder)

View File

@ -1,3 +1,4 @@
import { AccountService } from '@ghostfolio/api/app/account/account.service';
import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; import { CacheService } from '@ghostfolio/api/app/cache/cache.service';
import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module';
import { UserModule } from '@ghostfolio/api/app/user/user.module'; import { UserModule } from '@ghostfolio/api/app/user/user.module';
@ -24,7 +25,7 @@ import { OrderService } from './order.service';
UserModule UserModule
], ],
controllers: [OrderController], controllers: [OrderController],
providers: [CacheService, OrderService], providers: [AccountService, CacheService, OrderService],
exports: [OrderService] exports: [OrderService]
}) })
export class OrderModule {} export class OrderModule {}

View File

@ -1,3 +1,4 @@
import { AccountService } from '@ghostfolio/api/app/account/account.service';
import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; import { CacheService } from '@ghostfolio/api/app/cache/cache.service';
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
@ -13,6 +14,7 @@ import { Activity } from './interfaces/activities.interface';
@Injectable() @Injectable()
export class OrderService { export class OrderService {
public constructor( public constructor(
private readonly accountService: AccountService,
private readonly cacheService: CacheService, private readonly cacheService: CacheService,
private readonly exchangeRateDataService: ExchangeRateDataService, private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly dataGatheringService: DataGatheringService, private readonly dataGatheringService: DataGatheringService,
@ -47,7 +49,24 @@ export class OrderService {
}); });
} }
public async createOrder(data: Prisma.OrderCreateInput): Promise<Order> { public async createOrder(
data: Prisma.OrderCreateInput & { accountId?: string; userId: string }
): Promise<Order> {
const defaultAccount = (
await this.accountService.getAccounts(data.userId)
).find((account) => {
return account.isDefault === true;
});
const Account = {
connect: {
id_userId: {
userId: data.userId,
id: data.accountId ?? defaultAccount?.id
}
}
};
const isDraft = isAfter(data.date as Date, endOfToday()); const isDraft = isAfter(data.date as Date, endOfToday());
// Convert the symbol to uppercase to avoid case-sensitive duplicates // Convert the symbol to uppercase to avoid case-sensitive duplicates
@ -70,9 +89,15 @@ export class OrderService {
await this.cacheService.flush(); await this.cacheService.flush();
delete data.accountId;
delete data.userId;
const orderData: Prisma.OrderCreateInput = data;
return this.prismaService.order.create({ return this.prismaService.order.create({
data: { data: {
...data, ...orderData,
Account,
isDraft, isDraft,
symbol symbol
} }

View File

@ -4,9 +4,12 @@ import {
hasNotDefinedValuesInObject, hasNotDefinedValuesInObject,
nullifyValuesInObject nullifyValuesInObject
} from '@ghostfolio/api/helper/object.helper'; } from '@ghostfolio/api/helper/object.helper';
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor';
import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response.interceptor';
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { baseCurrency } from '@ghostfolio/common/config'; import { baseCurrency } from '@ghostfolio/common/config';
import { parseDate } from '@ghostfolio/common/helper';
import { import {
PortfolioChart, PortfolioChart,
PortfolioDetails, PortfolioDetails,
@ -25,12 +28,11 @@ import {
Inject, Inject,
Param, Param,
Query, Query,
Res, UseGuards,
UseGuards UseInterceptors
} from '@nestjs/common'; } from '@nestjs/common';
import { REQUEST } from '@nestjs/core'; import { REQUEST } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
import { Response } from 'express';
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface'; import { PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface';
@ -52,8 +54,7 @@ export class PortfolioController {
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async getChart( public async getChart(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string,
@Query('range') range, @Query('range') range
@Res() res: Response
): Promise<PortfolioChart> { ): Promise<PortfolioChart> {
const historicalDataContainer = await this.portfolioServiceStrategy const historicalDataContainer = await this.portfolioServiceStrategy
.get() .get()
@ -89,27 +90,29 @@ export class PortfolioController {
}); });
} }
return <any>res.json({ return {
hasError, hasError,
chart: chartData, chart: chartData,
isAllTimeHigh: historicalDataContainer.isAllTimeHigh, isAllTimeHigh: historicalDataContainer.isAllTimeHigh,
isAllTimeLow: historicalDataContainer.isAllTimeLow isAllTimeLow: historicalDataContainer.isAllTimeLow
}); };
} }
@Get('details') @Get('details')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInResponseInterceptor)
public async getDetails( public async getDetails(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string,
@Query('range') range, @Query('range') range
@Res() res: Response ): Promise<PortfolioDetails & { hasError: boolean }> {
): Promise<PortfolioDetails> {
if ( if (
this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') && this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') &&
this.request.user.subscription.type === 'Basic' this.request.user.subscription.type === 'Basic'
) { ) {
res.status(StatusCodes.FORBIDDEN); throw new HttpException(
return <any>res.json({ accounts: {}, holdings: {} }); getReasonPhrase(StatusCodes.FORBIDDEN),
StatusCodes.FORBIDDEN
);
} }
let hasError = false; let hasError = false;
@ -158,21 +161,22 @@ export class PortfolioController {
} }
} }
return <any>res.json({ accounts, hasError, holdings }); return { accounts, hasError, holdings };
} }
@Get('investments') @Get('investments')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async getInvestments( public async getInvestments(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string
@Res() res: Response
): Promise<PortfolioInvestments> { ): Promise<PortfolioInvestments> {
if ( if (
this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') && this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') &&
this.request.user.subscription.type === 'Basic' this.request.user.subscription.type === 'Basic'
) { ) {
res.status(StatusCodes.FORBIDDEN); throw new HttpException(
return <any>res.json({}); getReasonPhrase(StatusCodes.FORBIDDEN),
StatusCodes.FORBIDDEN
);
} }
let investments = await this.portfolioServiceStrategy let investments = await this.portfolioServiceStrategy
@ -194,15 +198,14 @@ export class PortfolioController {
})); }));
} }
return <any>res.json({ firstOrderDate: investments[0]?.date, investments }); return { firstOrderDate: parseDate(investments[0]?.date), investments };
} }
@Get('performance') @Get('performance')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async getPerformance( public async getPerformance(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string,
@Query('range') range, @Query('range') range
@Res() res: Response
): Promise<{ hasErrors: boolean; performance: PortfolioPerformance }> { ): Promise<{ hasErrors: boolean; performance: PortfolioPerformance }> {
const performanceInformation = await this.portfolioServiceStrategy const performanceInformation = await this.portfolioServiceStrategy
.get() .get()
@ -218,15 +221,15 @@ export class PortfolioController {
); );
} }
return <any>res.json(performanceInformation); return performanceInformation;
} }
@Get('positions') @Get('positions')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInResponseInterceptor)
public async getPositions( public async getPositions(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string,
@Query('range') range, @Query('range') range
@Res() res: Response
): Promise<PortfolioPositions> { ): Promise<PortfolioPositions> {
const result = await this.portfolioServiceStrategy const result = await this.portfolioServiceStrategy
.get() .get()
@ -246,13 +249,12 @@ export class PortfolioController {
}); });
} }
return <any>res.json(result); return result;
} }
@Get('public/:accessId') @Get('public/:accessId')
public async getPublic( public async getPublic(
@Param('accessId') accessId, @Param('accessId') accessId
@Res() res: Response
): Promise<PortfolioPublicDetails> { ): Promise<PortfolioPublicDetails> {
const access = await this.accessService.access({ id: accessId }); const access = await this.accessService.access({ id: accessId });
const user = await this.userService.user({ const user = await this.userService.user({
@ -260,8 +262,10 @@ export class PortfolioController {
}); });
if (!access) { if (!access) {
res.status(StatusCodes.NOT_FOUND); throw new HttpException(
return <any>res.json({ accounts: {}, holdings: {} }); getReasonPhrase(StatusCodes.NOT_FOUND),
StatusCodes.NOT_FOUND
);
} }
let hasDetails = true; let hasDetails = true;
@ -304,7 +308,7 @@ export class PortfolioController {
} }
} }
return <any>res.json(portfolioPublicDetails); return portfolioPublicDetails;
} }
@Get('summary') @Get('summary')
@ -337,15 +341,17 @@ export class PortfolioController {
return summary; return summary;
} }
@Get('position/:symbol') @Get('position/:dataSource/:symbol')
@UseInterceptors(TransformDataSourceInRequestInterceptor)
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async getPosition( public async getPosition(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string,
@Param('dataSource') dataSource,
@Param('symbol') symbol @Param('symbol') symbol
): Promise<PortfolioPositionDetail> { ): Promise<PortfolioPositionDetail> {
let position = await this.portfolioServiceStrategy let position = await this.portfolioServiceStrategy
.get() .get()
.getPosition(impersonationId, symbol); .getPosition(dataSource, impersonationId, symbol);
if (position) { if (position) {
if ( if (
@ -374,21 +380,18 @@ export class PortfolioController {
@Get('report') @Get('report')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async getReport( public async getReport(
@Headers('impersonation-id') impersonationId: string, @Headers('impersonation-id') impersonationId: string
@Res() res: Response
): Promise<PortfolioReport> { ): Promise<PortfolioReport> {
if ( if (
this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') && this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') &&
this.request.user.subscription.type === 'Basic' this.request.user.subscription.type === 'Basic'
) { ) {
res.status(StatusCodes.FORBIDDEN); throw new HttpException(
return <any>res.json({ rules: [] }); getReasonPhrase(StatusCodes.FORBIDDEN),
} StatusCodes.FORBIDDEN
return <any>(
res.json(
await this.portfolioServiceStrategy.get().getReport(impersonationId)
)
); );
} }
return await this.portfolioServiceStrategy.get().getReport(impersonationId);
}
} }

View File

@ -357,6 +357,7 @@ export class PortfolioServiceNew {
assetSubClass: symbolProfile.assetSubClass, assetSubClass: symbolProfile.assetSubClass,
countries: symbolProfile.countries, countries: symbolProfile.countries,
currency: item.currency, currency: item.currency,
dataSource: symbolProfile.dataSource,
exchange: dataProviderResponse.exchange, exchange: dataProviderResponse.exchange,
grossPerformance: item.grossPerformance?.toNumber() ?? 0, grossPerformance: item.grossPerformance?.toNumber() ?? 0,
grossPerformancePercent: grossPerformancePercent:
@ -397,6 +398,7 @@ export class PortfolioServiceNew {
} }
public async getPosition( public async getPosition(
aDataSource: DataSource,
aImpersonationId: string, aImpersonationId: string,
aSymbol: string aSymbol: string
): Promise<PortfolioPositionDetail> { ): Promise<PortfolioPositionDetail> {
@ -405,7 +407,12 @@ export class PortfolioServiceNew {
const orders = ( const orders = (
await this.orderService.getOrders({ userCurrency, userId }) await this.orderService.getOrders({ userCurrency, userId })
).filter((order) => order.symbol === aSymbol); ).filter(({ SymbolProfile }) => {
return (
SymbolProfile.dataSource === aDataSource &&
SymbolProfile.symbol === aSymbol
);
});
if (orders.length <= 0) { if (orders.length <= 0) {
return { return {

View File

@ -345,6 +345,7 @@ export class PortfolioService {
assetSubClass: symbolProfile.assetSubClass, assetSubClass: symbolProfile.assetSubClass,
countries: symbolProfile.countries, countries: symbolProfile.countries,
currency: item.currency, currency: item.currency,
dataSource: symbolProfile.dataSource,
exchange: dataProviderResponse.exchange, exchange: dataProviderResponse.exchange,
grossPerformance: item.grossPerformance?.toNumber() ?? 0, grossPerformance: item.grossPerformance?.toNumber() ?? 0,
grossPerformancePercent: grossPerformancePercent:
@ -385,6 +386,7 @@ export class PortfolioService {
} }
public async getPosition( public async getPosition(
aDataSource: DataSource,
aImpersonationId: string, aImpersonationId: string,
aSymbol: string aSymbol: string
): Promise<PortfolioPositionDetail> { ): Promise<PortfolioPositionDetail> {
@ -393,7 +395,12 @@ export class PortfolioService {
const orders = ( const orders = (
await this.orderService.getOrders({ userCurrency, userId }) await this.orderService.getOrders({ userCurrency, userId })
).filter((order) => order.symbol === aSymbol); ).filter(({ SymbolProfile }) => {
return (
SymbolProfile.dataSource === aDataSource &&
SymbolProfile.symbol === aSymbol
);
});
if (orders.length <= 0) { if (orders.length <= 0) {
return { return {
@ -467,7 +474,6 @@ export class PortfolioService {
} = position; } = position;
// Convert investment, gross and net performance to currency of user // Convert investment, gross and net performance to currency of user
const userCurrency = this.request.user.Settings.currency;
const investment = this.exchangeRateDataService.toCurrency( const investment = this.exchangeRateDataService.toCurrency(
position.investment?.toNumber(), position.investment?.toNumber(),
currency, currency,

View File

@ -7,6 +7,7 @@ import {
Body, Body,
Controller, Controller,
Get, Get,
HttpCode,
HttpException, HttpException,
Inject, Inject,
Logger, Logger,
@ -17,7 +18,6 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { REQUEST } from '@nestjs/core'; import { REQUEST } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
import { Response } from 'express';
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { SubscriptionService } from './subscription.service'; import { SubscriptionService } from './subscription.service';
@ -32,11 +32,9 @@ export class SubscriptionController {
) {} ) {}
@Post('redeem-coupon') @Post('redeem-coupon')
@HttpCode(StatusCodes.OK)
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
public async redeemCoupon( public async redeemCoupon(@Body() { couponCode }: { couponCode: string }) {
@Body() { couponCode }: { couponCode: string },
@Res() res: Response
) {
if (!this.request.user) { if (!this.request.user) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.FORBIDDEN), getReasonPhrase(StatusCodes.FORBIDDEN),
@ -74,12 +72,10 @@ export class SubscriptionController {
`Subscription for user '${this.request.user.id}' has been created with coupon` `Subscription for user '${this.request.user.id}' has been created with coupon`
); );
res.status(StatusCodes.OK); return {
return <any>res.json({
message: getReasonPhrase(StatusCodes.OK), message: getReasonPhrase(StatusCodes.OK),
statusCode: StatusCodes.OK statusCode: StatusCodes.OK
}); };
} }
@Get('stripe/callback') @Get('stripe/callback')

View File

@ -1,3 +1,5 @@
import { TransformDataSourceInRequestInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-request.interceptor';
import { TransformDataSourceInResponseInterceptor } from '@ghostfolio/api/interceptors/transform-data-source-in-response.interceptor';
import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces'; import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces';
import { import {
Controller, Controller,
@ -5,7 +7,8 @@ import {
HttpException, HttpException,
Param, Param,
Query, Query,
UseGuards UseGuards,
UseInterceptors
} from '@nestjs/common'; } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport'; import { AuthGuard } from '@nestjs/passport';
import { DataSource } from '@prisma/client'; import { DataSource } from '@prisma/client';
@ -25,6 +28,7 @@ export class SymbolController {
*/ */
@Get('lookup') @Get('lookup')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInResponseInterceptor)
public async lookupSymbol( public async lookupSymbol(
@Query() { query = '' } @Query() { query = '' }
): Promise<{ items: LookupItem[] }> { ): Promise<{ items: LookupItem[] }> {
@ -43,6 +47,8 @@ export class SymbolController {
*/ */
@Get(':dataSource/:symbol') @Get(':dataSource/:symbol')
@UseGuards(AuthGuard('jwt')) @UseGuards(AuthGuard('jwt'))
@UseInterceptors(TransformDataSourceInRequestInterceptor)
@UseInterceptors(TransformDataSourceInResponseInterceptor)
public async getSymbolData( public async getSymbolData(
@Param('dataSource') dataSource: DataSource, @Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string, @Param('symbol') symbol: string,

View File

@ -0,0 +1,39 @@
import { decodeDataSource } from '@ghostfolio/common/helper';
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { ConfigurationService } from '../services/configuration.service';
@Injectable()
export class TransformDataSourceInRequestInterceptor<T>
implements NestInterceptor<T, any>
{
public constructor(
private readonly configurationService: ConfigurationService
) {}
public intercept(
context: ExecutionContext,
next: CallHandler<T>
): Observable<any> {
const http = context.switchToHttp();
const request = http.getRequest();
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') === true) {
if (request.body.dataSource) {
request.body.dataSource = decodeDataSource(request.body.dataSource);
}
if (request.params.dataSource) {
request.params.dataSource = decodeDataSource(request.params.dataSource);
}
}
return next.handle();
}
}

View File

@ -0,0 +1,73 @@
import { encodeDataSource } from '@ghostfolio/common/helper';
import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ConfigurationService } from '../services/configuration.service';
@Injectable()
export class TransformDataSourceInResponseInterceptor<T>
implements NestInterceptor<T, any>
{
public constructor(
private readonly configurationService: ConfigurationService
) {}
public intercept(
context: ExecutionContext,
next: CallHandler<T>
): Observable<any> {
return next.handle().pipe(
map((data: any) => {
if (
this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION') === true
) {
if (data.activities) {
data.activities.map((activity) => {
activity.SymbolProfile.dataSource = encodeDataSource(
activity.SymbolProfile.dataSource
);
activity.dataSource = encodeDataSource(activity.dataSource);
return activity;
});
}
if (data.dataSource) {
data.dataSource = encodeDataSource(data.dataSource);
}
if (data.holdings) {
for (const symbol of Object.keys(data.holdings)) {
if (data.holdings[symbol].dataSource) {
data.holdings[symbol].dataSource = encodeDataSource(
data.holdings[symbol].dataSource
);
}
}
}
if (data.items) {
data.items.map((item) => {
item.dataSource = encodeDataSource(item.dataSource);
return item;
});
}
if (data.positions) {
data.positions.map((position) => {
position.dataSource = encodeDataSource(position.dataSource);
return position;
});
}
}
return data;
})
);
}
}

View File

@ -5,6 +5,7 @@
"AVAX": "Avalanche", "AVAX": "Avalanche",
"DOT": "Polkadot", "DOT": "Polkadot",
"MATIC": "Polygon", "MATIC": "Polygon",
"MINA": "Mina Protocol",
"SHIB": "Shiba Inu", "SHIB": "Shiba Inu",
"SOL": "Solana", "SOL": "Solana",
"UNI3": "Uniswap" "UNI3": "Uniswap"

View File

@ -473,9 +473,18 @@ export class DataGatheringService {
private async getSymbols7D(): Promise<IDataGatheringItem[]> { private async getSymbols7D(): Promise<IDataGatheringItem[]> {
const startDate = subDays(resetHours(new Date()), 7); const startDate = subDays(resetHours(new Date()), 7);
const symbolProfiles = await this.prismaService.symbolProfile.findMany({
orderBy: [{ symbol: 'asc' }],
select: {
dataSource: true,
scraperConfiguration: true,
symbol: true
}
});
// Only consider symbols with incomplete market data for the last // Only consider symbols with incomplete market data for the last
// 7 days // 7 days
const symbolsToGather = ( const symbolsNotToGather = (
await this.prismaService.marketData.groupBy({ await this.prismaService.marketData.groupBy({
_count: true, _count: true,
by: ['symbol'], by: ['symbol'],
@ -485,24 +494,15 @@ export class DataGatheringService {
}) })
) )
.filter((group) => { .filter((group) => {
return group._count < 6; return group._count >= 6;
}) })
.map((group) => { .map((group) => {
return group.symbol; return group.symbol;
}); });
const symbolProfilesToGather = ( const symbolProfilesToGather = symbolProfiles
await this.prismaService.symbolProfile.findMany({
orderBy: [{ symbol: 'asc' }],
select: {
dataSource: true,
scraperConfiguration: true,
symbol: true
}
})
)
.filter(({ symbol }) => { .filter(({ symbol }) => {
return symbolsToGather.includes(symbol); return !symbolsNotToGather.includes(symbol);
}) })
.map((symbolProfile) => { .map((symbolProfile) => {
return { return {
@ -514,7 +514,7 @@ export class DataGatheringService {
const currencyPairsToGather = this.exchangeRateDataService const currencyPairsToGather = this.exchangeRateDataService
.getCurrencyPairs() .getCurrencyPairs()
.filter(({ symbol }) => { .filter(({ symbol }) => {
return symbolsToGather.includes(symbol); return !symbolsNotToGather.includes(symbol);
}) })
.map(({ dataSource, symbol }) => { .map(({ dataSource, symbol }) => {
return { return {

View File

@ -9,6 +9,21 @@ import { DataSource, MarketData, Prisma } from '@prisma/client';
export class MarketDataService { export class MarketDataService {
public constructor(private readonly prismaService: PrismaService) {} public constructor(private readonly prismaService: PrismaService) {}
public async deleteMany({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
return this.prismaService.marketData.deleteMany({
where: {
dataSource,
symbol
}
});
}
public async get({ public async get({
date, date,
symbol symbol

View File

@ -4,14 +4,26 @@ import { UNKNOWN_KEY } from '@ghostfolio/common/config';
import { Country } from '@ghostfolio/common/interfaces/country.interface'; import { Country } from '@ghostfolio/common/interfaces/country.interface';
import { Sector } from '@ghostfolio/common/interfaces/sector.interface'; import { Sector } from '@ghostfolio/common/interfaces/sector.interface';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Prisma, SymbolProfile } from '@prisma/client'; import { DataSource, Prisma, SymbolProfile } from '@prisma/client';
import { continents, countries } from 'countries-list'; import { continents, countries } from 'countries-list';
import { ScraperConfiguration } from './data-provider/ghostfolio-scraper-api/interfaces/scraper-configuration.interface'; import { ScraperConfiguration } from './data-provider/ghostfolio-scraper-api/interfaces/scraper-configuration.interface';
@Injectable() @Injectable()
export class SymbolProfileService { export class SymbolProfileService {
constructor(private readonly prismaService: PrismaService) {} public constructor(private readonly prismaService: PrismaService) {}
public async delete({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
return this.prismaService.symbolProfile.delete({
where: { dataSource_symbol: { dataSource, symbol } }
});
}
public async getSymbolProfiles( public async getSymbolProfiles(
symbols: string[] symbols: string[]

View File

@ -20,6 +20,7 @@ import { takeUntil } from 'rxjs/operators';
templateUrl: './admin-market-data.html' templateUrl: './admin-market-data.html'
}) })
export class AdminMarketDataComponent implements OnDestroy, OnInit { export class AdminMarketDataComponent implements OnDestroy, OnInit {
public currentDataSource: DataSource;
public currentSymbol: string; public currentSymbol: string;
public defaultDateFormat = DEFAULT_DATE_FORMAT; public defaultDateFormat = DEFAULT_DATE_FORMAT;
public marketData: AdminMarketDataItem[] = []; public marketData: AdminMarketDataItem[] = [];
@ -43,6 +44,19 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
this.fetchAdminMarketData(); this.fetchAdminMarketData();
} }
public onDeleteProfileData({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
this.adminService
.deleteProfileData({ dataSource, symbol })
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => {});
}
public onGatherProfileDataBySymbol({ public onGatherProfileDataBySymbol({
dataSource, dataSource,
symbol symbol
@ -69,22 +83,33 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
.subscribe(() => {}); .subscribe(() => {});
} }
public setCurrentSymbol(aSymbol: string) {
this.marketDataDetails = [];
if (this.currentSymbol === aSymbol) {
this.currentSymbol = '';
} else {
this.currentSymbol = aSymbol;
this.fetchAdminMarketDataBySymbol(this.currentSymbol);
}
}
public onMarketDataChanged(withRefresh: boolean = false) { public onMarketDataChanged(withRefresh: boolean = false) {
if (withRefresh) { if (withRefresh) {
this.fetchAdminMarketData(); this.fetchAdminMarketData();
this.fetchAdminMarketDataBySymbol(this.currentSymbol); this.fetchAdminMarketDataBySymbol({
dataSource: this.currentDataSource,
symbol: this.currentSymbol
});
}
}
public setCurrentProfile({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
this.marketDataDetails = [];
if (this.currentSymbol === symbol) {
this.currentDataSource = undefined;
this.currentSymbol = '';
} else {
this.currentDataSource = dataSource;
this.currentSymbol = symbol;
this.fetchAdminMarketDataBySymbol({ dataSource, symbol });
} }
} }
@ -104,9 +129,15 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
}); });
} }
private fetchAdminMarketDataBySymbol(aSymbol: string) { private fetchAdminMarketDataBySymbol({
this.dataService dataSource,
.fetchAdminMarketDataBySymbol(aSymbol) symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
this.adminService
.fetchAdminMarketDataBySymbol({ dataSource, symbol })
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ marketData }) => { .subscribe(({ marketData }) => {
this.marketDataDetails = marketData; this.marketDataDetails = marketData;

View File

@ -16,7 +16,7 @@
<ng-container *ngFor="let item of marketData; let i = index"> <ng-container *ngFor="let item of marketData; let i = index">
<tr <tr
class="cursor-pointer mat-row" class="cursor-pointer mat-row"
(click)="setCurrentSymbol(item.symbol)" (click)="setCurrentProfile({ dataSource: item.dataSource, symbol: item.symbol })"
> >
<td class="mat-cell px-1 py-2">{{ item.symbol }}</td> <td class="mat-cell px-1 py-2">{{ item.symbol }}</td>
<td class="mat-cell px-1 py-2">{{ item.dataSource }}</td> <td class="mat-cell px-1 py-2">{{ item.dataSource }}</td>
@ -49,11 +49,19 @@
> >
Gather Profile Data Gather Profile Data
</button> </button>
<button
i18n
mat-menu-item
[disabled]="item.activityCount !== 0"
(click)="onDeleteProfileData({dataSource: item.dataSource, symbol: item.symbol})"
>
Delete Profile Data
</button>
</mat-menu> </mat-menu>
</td> </td>
</tr> </tr>
<tr *ngIf="currentSymbol === item.symbol" class="mat-row"> <tr *ngIf="currentSymbol === item.symbol" class="mat-row">
<td class="p-1" colspan="4"> <td class="p-1" colspan="6">
<gf-admin-market-data-detail <gf-admin-market-data-detail
[dataSource]="item.dataSource" [dataSource]="item.dataSource"
[marketData]="marketDataDetails" [marketData]="marketDataDetails"

View File

@ -12,6 +12,7 @@ import { defaultDateRangeOptions } from '@ghostfolio/common/config';
import { Position, User } from '@ghostfolio/common/interfaces'; import { Position, User } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { DateRange } from '@ghostfolio/common/types'; import { DateRange } from '@ghostfolio/common/types';
import { DataSource } from '@prisma/client';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
@ -47,8 +48,15 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit {
route.queryParams route.queryParams
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((params) => { .subscribe((params) => {
if (params['positionDetailDialog'] && params['symbol']) { if (
this.openPositionDialog({ symbol: params['symbol'] }); params['dataSource'] &&
params['positionDetailDialog'] &&
params['symbol']
) {
this.openPositionDialog({
dataSource: params['dataSource'],
symbol: params['symbol']
});
} }
}); });
@ -91,7 +99,13 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit {
this.unsubscribeSubject.complete(); this.unsubscribeSubject.complete();
} }
private openPositionDialog({ symbol }: { symbol: string }) { private openPositionDialog({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
this.userService this.userService
.get() .get()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
@ -101,6 +115,7 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit {
const dialogRef = this.dialog.open(PositionDetailDialog, { const dialogRef = this.dialog.open(PositionDetailDialog, {
autoFocus: false, autoFocus: false,
data: { data: {
dataSource,
symbol, symbol,
baseCurrency: this.user?.settings?.baseCurrency, baseCurrency: this.user?.settings?.baseCurrency,
deviceType: this.deviceType, deviceType: this.deviceType,

View File

@ -4,9 +4,8 @@ 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 { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config'; import { ghostfolioFearAndGreedIndexSymbol } from '@ghostfolio/common/config';
import { resetHours } from '@ghostfolio/common/helper'; import { resetHours } from '@ghostfolio/common/helper';
import { User } from '@ghostfolio/common/interfaces'; import { InfoItem, User } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { DataSource } from '@prisma/client';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
@ -19,6 +18,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
public fearAndGreedIndex: number; public fearAndGreedIndex: number;
public hasPermissionToAccessFearAndGreedIndex: boolean; public hasPermissionToAccessFearAndGreedIndex: boolean;
public historicalData: HistoricalDataItem[]; public historicalData: HistoricalDataItem[];
public info: InfoItem;
public isLoading = true; public isLoading = true;
public readonly numberOfDays = 90; public readonly numberOfDays = 90;
public user: User; public user: User;
@ -33,6 +33,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
private dataService: DataService, private dataService: DataService,
private userService: UserService private userService: UserService
) { ) {
this.info = this.dataService.fetchInfo();
this.isLoading = true; this.isLoading = true;
this.userService.stateChanged this.userService.stateChanged
@ -49,7 +50,7 @@ export class HomeMarketComponent implements OnDestroy, OnInit {
if (this.hasPermissionToAccessFearAndGreedIndex) { if (this.hasPermissionToAccessFearAndGreedIndex) {
this.dataService this.dataService
.fetchSymbolItem({ .fetchSymbolItem({
dataSource: DataSource.RAKUTEN, dataSource: this.info.fearAndGreedDataSource,
includeHistoricalData: this.numberOfDays, includeHistoricalData: this.numberOfDays,
symbol: ghostfolioFearAndGreedIndexSymbol symbol: ghostfolioFearAndGreedIndexSymbol
}) })

View File

@ -1,6 +0,0 @@
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
export interface PositionDetailDialogParams {
deviceType: string;
historicalDataItems: LineChartItem[];
}

View File

@ -1,12 +0,0 @@
:host {
display: block;
.mat-dialog-content {
max-height: unset;
gf-line-chart {
aspect-ratio: 16 / 9;
margin: 0 -1rem;
}
}
}

View File

@ -1,94 +0,0 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Inject
} from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { DataService } from '@ghostfolio/client/services/data.service';
import { DATE_FORMAT } from '@ghostfolio/common/helper';
import { LineChartItem } from '@ghostfolio/ui/line-chart/interfaces/line-chart.interface';
import { isToday, parse } from 'date-fns';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { PositionDetailDialogParams } from './interfaces/interfaces';
@Component({
selector: 'gf-performance-chart-dialog',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: 'performance-chart-dialog.html',
styleUrls: ['./performance-chart-dialog.component.scss']
})
export class PerformanceChartDialog {
public benchmarkDataItems: LineChartItem[];
public benchmarkSymbol = 'VOO';
public currency: string;
public firstBuyDate: string;
public marketPrice: number;
public historicalDataItems: LineChartItem[];
private unsubscribeSubject = new Subject<void>();
public constructor(
private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService,
public dialogRef: MatDialogRef<PerformanceChartDialog>,
@Inject(MAT_DIALOG_DATA) public data: PositionDetailDialogParams
) {
this.dataService
.fetchPositionDetail(this.benchmarkSymbol)
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(({ currency, firstBuyDate, historicalData, marketPrice }) => {
this.benchmarkDataItems = [];
this.currency = currency;
this.firstBuyDate = firstBuyDate;
this.historicalDataItems = [];
this.marketPrice = marketPrice;
let coefficient = 1;
this.historicalDataItems = this.data.historicalDataItems;
this.historicalDataItems?.forEach((historicalDataItem) => {
const benchmarkItem = historicalData.find((item) => {
return item.date === historicalDataItem.date;
});
if (benchmarkItem) {
if (coefficient === 1) {
coefficient = historicalDataItem.value / benchmarkItem.value || 1;
}
this.benchmarkDataItems.push({
date: historicalDataItem.date,
value: benchmarkItem.value * coefficient
});
} else if (
isToday(parse(historicalDataItem.date, DATE_FORMAT, new Date()))
) {
this.benchmarkDataItems.push({
date: historicalDataItem.date,
value: marketPrice * coefficient
});
} else {
this.benchmarkDataItems.push({
date: historicalDataItem.date,
value: undefined
});
}
});
this.changeDetectorRef.markForCheck();
});
}
public onClose(): void {
this.dialogRef.close();
}
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
}

View File

@ -1,27 +0,0 @@
<gf-dialog-header
mat-dialog-title
title="Performance"
[deviceType]="data.deviceType"
(closeButtonClicked)="onClose()"
></gf-dialog-header>
<div mat-dialog-content>
<div class="container p-0">
<gf-line-chart
class="mb-4"
symbol="Performance"
[benchmarkDataItems]="benchmarkDataItems"
[historicalDataItems]="historicalDataItems"
[showGradient]="true"
[showLegend]="true"
[showXAxis]="true"
[showYAxis]="false"
></gf-line-chart>
</div>
</div>
<gf-dialog-footer
mat-dialog-actions
[deviceType]="data.deviceType"
(closeButtonClicked)="onClose()"
></gf-dialog-footer>

View File

@ -1,28 +0,0 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule } from '@angular/material/dialog';
import { GfLineChartModule } from '@ghostfolio/ui/line-chart/line-chart.module';
import { GfValueModule } from '@ghostfolio/ui/value';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { GfDialogFooterModule } from '../dialog-footer/dialog-footer.module';
import { GfDialogHeaderModule } from '../dialog-header/dialog-header.module';
import { PerformanceChartDialog } from './performance-chart-dialog.component';
@NgModule({
declarations: [PerformanceChartDialog],
exports: [],
imports: [
CommonModule,
GfDialogFooterModule,
GfDialogHeaderModule,
GfLineChartModule,
GfValueModule,
MatButtonModule,
MatDialogModule,
NgxSkeletonLoaderModule
],
providers: []
})
export class GfPerformanceChartDialogModule {}

View File

@ -1,5 +1,8 @@
import { DataSource } from '@prisma/client';
export interface PositionDetailDialogParams { export interface PositionDetailDialogParams {
baseCurrency: string; baseCurrency: string;
dataSource: DataSource;
deviceType: string; deviceType: string;
locale: string; locale: string;
symbol: string; symbol: string;

View File

@ -59,7 +59,10 @@ export class PositionDetailDialog implements OnDestroy, OnInit {
public ngOnInit(): void { public ngOnInit(): void {
this.dataService this.dataService
.fetchPositionDetail(this.data.symbol) .fetchPositionDetail({
dataSource: this.data.dataSource,
symbol: this.data.symbol
})
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe( .subscribe(
({ ({

View File

@ -3,7 +3,11 @@
<a <a
class="d-flex p-3 w-100" class="d-flex p-3 w-100"
[routerLink]="[]" [routerLink]="[]"
[queryParams]="{ positionDetailDialog: true, symbol: position?.symbol }" [queryParams]="{
dataSource: position?.dataSource,
positionDetailDialog: true,
symbol: position?.symbol
}"
> >
<div class="d-flex mr-2"> <div class="d-flex mr-2">
<gf-trend-indicator <gf-trend-indicator

View File

@ -108,7 +108,7 @@
}" }"
(click)=" (click)="
!ignoreAssetSubClasses.includes(row.assetSubClass) && !ignoreAssetSubClasses.includes(row.assetSubClass) &&
onOpenPositionDialog({ symbol: row.symbol }) onOpenPositionDialog({ dataSource: row.dataSource, symbol: row.symbol })
" "
></tr> ></tr>
</table> </table>

View File

@ -14,7 +14,7 @@ import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table'; import { MatTableDataSource } from '@angular/material/table';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { PortfolioPosition } from '@ghostfolio/common/interfaces'; import { PortfolioPosition } from '@ghostfolio/common/interfaces';
import { AssetClass, Order as OrderModel } from '@prisma/client'; import { AssetClass, DataSource, Order as OrderModel } from '@prisma/client';
import { Subject, Subscription } from 'rxjs'; import { Subject, Subscription } from 'rxjs';
@Component({ @Component({
@ -75,9 +75,15 @@ export class PositionsTableComponent implements OnChanges, OnDestroy, OnInit {
this.dataSource.filter = filterValue.trim().toLowerCase(); this.dataSource.filter = filterValue.trim().toLowerCase();
}*/ }*/
public onOpenPositionDialog({ symbol }: { symbol: string }): void { public onOpenPositionDialog({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}): void {
this.router.navigate([], { this.router.navigate([], {
queryParams: { positionDetailDialog: true, symbol } queryParams: { dataSource, symbol, positionDetailDialog: true }
}); });
} }

View File

@ -14,7 +14,7 @@ import {
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { ToggleOption } from '@ghostfolio/common/types'; import { ToggleOption } from '@ghostfolio/common/types';
import { AssetClass } from '@prisma/client'; import { AssetClass, DataSource } from '@prisma/client';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, Subscription } from 'rxjs'; import { Subject, Subscription } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
@ -84,8 +84,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
this.routeQueryParams = route.queryParams this.routeQueryParams = route.queryParams
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((params) => { .subscribe((params) => {
if (params['positionDetailDialog'] && params['symbol']) { if (
params['dataSource'] &&
params['positionDetailDialog'] &&
params['symbol']
) {
this.openPositionDialog({ this.openPositionDialog({
dataSource: params['dataSource'],
symbol: params['symbol'] symbol: params['symbol']
}); });
} }
@ -291,7 +296,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
this.unsubscribeSubject.complete(); this.unsubscribeSubject.complete();
} }
private openPositionDialog({ symbol }: { symbol: string }) { private openPositionDialog({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
this.userService this.userService
.get() .get()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
@ -301,6 +312,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
const dialogRef = this.dialog.open(PositionDetailDialog, { const dialogRef = this.dialog.open(PositionDetailDialog, {
autoFocus: false, autoFocus: false,
data: { data: {
dataSource,
symbol, symbol,
baseCurrency: this.user?.settings?.baseCurrency, baseCurrency: this.user?.settings?.baseCurrency,
deviceType: this.deviceType, deviceType: this.deviceType,

View File

@ -107,18 +107,6 @@
<mat-datepicker #date disabled="false"></mat-datepicker> <mat-datepicker #date disabled="false"></mat-datepicker>
</mat-form-field> </mat-form-field>
</div> </div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Fee</mat-label>
<input
matInput
name="fee"
required
type="number"
[(ngModel)]="data.transaction.fee"
/>
</mat-form-field>
</div>
<div> <div>
<mat-form-field appearance="outline" class="w-100"> <mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Quantity</mat-label> <mat-label i18n>Quantity</mat-label>
@ -141,6 +129,7 @@
type="number" type="number"
[(ngModel)]="data.transaction.unitPrice" [(ngModel)]="data.transaction.unitPrice"
/> />
<span class="ml-2" matSuffix>{{ data.transaction.currency }}</span>
<button <button
*ngIf="currentMarketPrice && (data.transaction.type === 'BUY' || data.transaction.type === 'SELL')" *ngIf="currentMarketPrice && (data.transaction.type === 'BUY' || data.transaction.type === 'SELL')"
mat-icon-button mat-icon-button
@ -152,6 +141,19 @@
</button> </button>
</mat-form-field> </mat-form-field>
</div> </div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Fee</mat-label>
<input
matInput
name="fee"
required
type="number"
[(ngModel)]="data.transaction.fee"
/>
<span class="ml-2" matSuffix>{{ data.transaction.currency }}</span>
</mat-form-field>
</div>
</div> </div>
<div class="d-flex" mat-dialog-actions> <div class="d-flex" mat-dialog-actions>
<gf-value <gf-value

View File

@ -39,7 +39,6 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
public routeQueryParams: Subscription; public routeQueryParams: Subscription;
public user: User; public user: User;
private primaryDataSource: DataSource;
private unsubscribeSubject = new Subject<void>(); private unsubscribeSubject = new Subject<void>();
/** /**
@ -57,9 +56,6 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
private snackBar: MatSnackBar, private snackBar: MatSnackBar,
private userService: UserService private userService: UserService
) { ) {
const { primaryDataSource } = this.dataService.fetchInfo();
this.primaryDataSource = primaryDataSource;
this.routeQueryParams = route.queryParams this.routeQueryParams = route.queryParams
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((params) => { .subscribe((params) => {
@ -75,8 +71,13 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
} else { } else {
this.router.navigate(['.'], { relativeTo: this.route }); this.router.navigate(['.'], { relativeTo: this.route });
} }
} else if (params['positionDetailDialog'] && params['symbol']) { } else if (
params['dataSource'] &&
params['positionDetailDialog'] &&
params['symbol']
) {
this.openPositionDialog({ this.openPositionDialog({
dataSource: params['dataSource'],
symbol: params['symbol'] symbol: params['symbol']
}); });
} }
@ -190,8 +191,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
try { try {
await this.importTransactionsService.importJson({ await this.importTransactionsService.importJson({
content: content.orders, content: content.orders
defaultAccountId: this.defaultAccountId
}); });
this.handleImportSuccess(); this.handleImportSuccess();
@ -205,8 +205,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
try { try {
await this.importTransactionsService.importCsv({ await this.importTransactionsService.importCsv({
fileContent, fileContent,
defaultAccountId: this.defaultAccountId, userAccounts: this.user.accounts
primaryDataSource: this.primaryDataSource
}); });
this.handleImportSuccess(); this.handleImportSuccess();
@ -387,7 +386,13 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
}); });
} }
private openPositionDialog({ symbol }: { symbol: string }) { private openPositionDialog({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
this.userService this.userService
.get() .get()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
@ -397,6 +402,7 @@ export class TransactionsPageComponent implements OnDestroy, OnInit {
const dialogRef = this.dialog.open(PositionDetailDialog, { const dialogRef = this.dialog.open(PositionDetailDialog, {
autoFocus: false, autoFocus: false,
data: { data: {
dataSource,
symbol, symbol,
baseCurrency: this.user?.settings?.baseCurrency, baseCurrency: this.user?.settings?.baseCurrency,
deviceType: this.deviceType, deviceType: this.deviceType,

View File

@ -3,8 +3,10 @@ import { Injectable } from '@angular/core';
import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-data.dto'; import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-data.dto';
import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces'; import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces';
import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { DATE_FORMAT } from '@ghostfolio/common/helper';
import { AdminMarketDataDetails } from '@ghostfolio/common/interfaces';
import { DataSource, MarketData } from '@prisma/client'; import { DataSource, MarketData } from '@prisma/client';
import { format } from 'date-fns'; import { format, parseISO } from 'date-fns';
import { map, Observable } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -12,6 +14,37 @@ import { format } from 'date-fns';
export class AdminService { export class AdminService {
public constructor(private http: HttpClient) {} public constructor(private http: HttpClient) {}
public deleteProfileData({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
return this.http.delete<void>(
`/api/admin/profile-data/${dataSource}/${symbol}`
);
}
public fetchAdminMarketDataBySymbol({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}): Observable<AdminMarketDataDetails> {
return this.http
.get<any>(`/api/admin/market-data/${dataSource}/${symbol}`)
.pipe(
map((data) => {
for (const item of data.marketData) {
item.date = parseISO(item.date);
}
return data;
})
);
}
public gatherMax() { public gatherMax() {
return this.http.post<void>(`/api/admin/gather/max`, {}); return this.http.post<void>(`/api/admin/gather/max`, {});
} }

View File

@ -18,7 +18,6 @@ import {
Accounts, Accounts,
AdminData, AdminData,
AdminMarketData, AdminMarketData,
AdminMarketDataDetails,
Export, Export,
InfoItem, InfoItem,
PortfolioChart, PortfolioChart,
@ -69,19 +68,6 @@ export class DataService {
return this.http.get<AdminMarketData>('/api/admin/market-data'); return this.http.get<AdminMarketData>('/api/admin/market-data');
} }
public fetchAdminMarketDataBySymbol(
aSymbol: string
): Observable<AdminMarketDataDetails> {
return this.http.get<any>(`/api/admin/market-data/${aSymbol}`).pipe(
map((data) => {
for (const item of data.marketData) {
item.date = parseISO(item.date);
}
return data;
})
);
}
public deleteAccess(aId: string) { public deleteAccess(aId: string) {
return this.http.delete<any>(`/api/access/${aId}`); return this.http.delete<any>(`/api/access/${aId}`);
} }
@ -141,7 +127,7 @@ export class DataService {
includeHistoricalData, includeHistoricalData,
symbol symbol
}: { }: {
dataSource: DataSource; dataSource: DataSource | string;
includeHistoricalData?: number; includeHistoricalData?: number;
symbol: string; symbol: string;
}) { }) {
@ -225,8 +211,16 @@ export class DataService {
); );
} }
public fetchPositionDetail(aSymbol: string) { public fetchPositionDetail({
return this.http.get<any>(`/api/portfolio/position/${aSymbol}`).pipe( dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}) {
return this.http
.get<any>(`/api/portfolio/position/${dataSource}/${symbol}`)
.pipe(
map((data) => { map((data) => {
if (data.orders) { if (data.orders) {
for (const order of data.orders) { for (const order of data.orders) {

View File

@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
import { DataSource, Type } from '@prisma/client'; import { Account, DataSource, Type } from '@prisma/client';
import { parse } from 'date-fns'; import { parse } from 'date-fns';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import { parse as csvToJson } from 'papaparse'; import { parse as csvToJson } from 'papaparse';
@ -12,7 +12,9 @@ import { catchError } from 'rxjs/operators';
providedIn: 'root' providedIn: 'root'
}) })
export class ImportTransactionsService { export class ImportTransactionsService {
private static ACCOUNT_KEYS = ['account', 'accountid'];
private static CURRENCY_KEYS = ['ccy', 'currency']; private static CURRENCY_KEYS = ['ccy', 'currency'];
private static DATA_SOURCE_KEYS = ['datasource'];
private static DATE_KEYS = ['date']; private static DATE_KEYS = ['date'];
private static FEE_KEYS = ['commission', 'fee']; private static FEE_KEYS = ['commission', 'fee'];
private static QUANTITY_KEYS = ['qty', 'quantity', 'shares', 'units']; private static QUANTITY_KEYS = ['qty', 'quantity', 'shares', 'units'];
@ -23,13 +25,11 @@ export class ImportTransactionsService {
public constructor(private http: HttpClient) {} public constructor(private http: HttpClient) {}
public async importCsv({ public async importCsv({
defaultAccountId,
fileContent, fileContent,
primaryDataSource userAccounts
}: { }: {
defaultAccountId: string;
fileContent: string; fileContent: string;
primaryDataSource: DataSource; userAccounts: Account[];
}) { }) {
const content = csvToJson(fileContent, { const content = csvToJson(fileContent, {
dynamicTyping: true, dynamicTyping: true,
@ -38,12 +38,11 @@ export class ImportTransactionsService {
}).data; }).data;
const orders: CreateOrderDto[] = []; const orders: CreateOrderDto[] = [];
for (const [index, item] of content.entries()) { for (const [index, item] of content.entries()) {
orders.push({ orders.push({
accountId: defaultAccountId, accountId: this.parseAccount({ item, userAccounts }),
currency: this.parseCurrency({ content, index, item }), currency: this.parseCurrency({ content, index, item }),
dataSource: primaryDataSource, dataSource: this.parseDataSource({ item }),
date: this.parseDate({ content, index, item }), date: this.parseDate({ content, index, item }),
fee: this.parseFee({ content, index, item }), fee: this.parseFee({ content, index, item }),
quantity: this.parseQuantity({ content, index, item }), quantity: this.parseQuantity({ content, index, item }),
@ -53,21 +52,13 @@ export class ImportTransactionsService {
}); });
} }
await this.importJson({ defaultAccountId, content: orders }); await this.importJson({ content: orders });
} }
public importJson({ public importJson({ content }: { content: CreateOrderDto[] }): Promise<void> {
content,
defaultAccountId
}: {
content: CreateOrderDto[];
defaultAccountId: string;
}): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.postImport({ this.postImport({
orders: content.map((order) => { orders: content
return { ...order, accountId: defaultAccountId };
})
}) })
.pipe( .pipe(
catchError((error) => { catchError((error) => {
@ -90,6 +81,29 @@ export class ImportTransactionsService {
}, {}); }, {});
} }
private parseAccount({
item,
userAccounts
}: {
item: any;
userAccounts: Account[];
}) {
item = this.lowercaseKeys(item);
for (const key of ImportTransactionsService.ACCOUNT_KEYS) {
if (item[key]) {
return userAccounts.find((account) => {
return (
account.id === item[key] ||
account.name.toLowerCase() === item[key].toLowerCase()
);
})?.id;
}
}
return undefined;
}
private parseCurrency({ private parseCurrency({
content, content,
index, index,
@ -110,6 +124,18 @@ export class ImportTransactionsService {
throw { message: `orders.${index}.currency is not valid`, orders: content }; throw { message: `orders.${index}.currency is not valid`, orders: content };
} }
private parseDataSource({ item }: { item: any }) {
item = this.lowercaseKeys(item);
for (const key of ImportTransactionsService.DATA_SOURCE_KEYS) {
if (item[key]) {
return DataSource[item[key].toUpperCase()];
}
}
return undefined;
}
private parseDate({ private parseDate({
content, content,
index, index,

View File

@ -1,4 +1,5 @@
import * as currencies from '@dinero.js/currencies'; import * as currencies from '@dinero.js/currencies';
import { DataSource } from '@prisma/client';
import { getDate, getMonth, getYear, parse, subDays } from 'date-fns'; import { getDate, getMonth, getYear, parse, subDays } from 'date-fns';
import { ghostfolioScraperApiSymbolPrefix } from './config'; import { ghostfolioScraperApiSymbolPrefix } from './config';
@ -7,6 +8,14 @@ export function capitalize(aString: string) {
return aString.charAt(0).toUpperCase() + aString.slice(1).toLowerCase(); return aString.charAt(0).toUpperCase() + aString.slice(1).toLowerCase();
} }
export function decodeDataSource(encodedDataSource: string) {
return Buffer.from(encodedDataSource, 'hex').toString();
}
export function encodeDataSource(aDataSource: DataSource) {
return Buffer.from(aDataSource, 'utf-8').toString('hex');
}
export function getBackgroundColor() { export function getBackgroundColor() {
return getCssVariable( return getCssVariable(
window.matchMedia('(prefers-color-scheme: dark)').matches window.matchMedia('(prefers-color-scheme: dark)').matches

View File

@ -1,16 +1,14 @@
import { DataSource } from '@prisma/client';
import { Statistics } from './statistics.interface'; import { Statistics } from './statistics.interface';
import { Subscription } from './subscription.interface'; import { Subscription } from './subscription.interface';
export interface InfoItem { export interface InfoItem {
currencies: string[]; currencies: string[];
demoAuthToken: string; demoAuthToken: string;
fearAndGreedDataSource?: string;
globalPermissions: string[]; globalPermissions: string[];
isReadOnlyMode?: boolean; isReadOnlyMode?: boolean;
lastDataGathering?: Date; lastDataGathering?: Date;
platforms: { id: string; name: string }[]; platforms: { id: string; name: string }[];
primaryDataSource: DataSource;
statistics: Statistics; statistics: Statistics;
stripePublicKey?: string; stripePublicKey?: string;
subscriptions: Subscription[]; subscriptions: Subscription[];

View File

@ -1,5 +1,5 @@
import { MarketState } from '@ghostfolio/api/services/interfaces/interfaces'; import { MarketState } from '@ghostfolio/api/services/interfaces/interfaces';
import { AssetClass, AssetSubClass } from '@prisma/client'; import { AssetClass, AssetSubClass, DataSource } from '@prisma/client';
import { Country } from './country.interface'; import { Country } from './country.interface';
import { Sector } from './sector.interface'; import { Sector } from './sector.interface';
@ -11,6 +11,7 @@ export interface PortfolioPosition {
assetSubClass?: AssetSubClass | 'CASH'; assetSubClass?: AssetSubClass | 'CASH';
countries: Country[]; countries: Country[];
currency: string; currency: string;
dataSource: DataSource;
exchange?: string; exchange?: string;
grossPerformance: number; grossPerformance: number;
grossPerformancePercent: number; grossPerformancePercent: number;

View File

@ -1,10 +1,11 @@
import { MarketState } from '@ghostfolio/api/services/interfaces/interfaces'; import { MarketState } from '@ghostfolio/api/services/interfaces/interfaces';
import { AssetClass } from '@prisma/client'; import { AssetClass, DataSource } from '@prisma/client';
export interface Position { export interface Position {
assetClass: AssetClass; assetClass: AssetClass;
averagePrice: number; averagePrice: number;
currency: string; currency: string;
dataSource: DataSource;
firstBuyDate: string; firstBuyDate: string;
grossPerformance?: number; grossPerformance?: number;
grossPerformancePercentage?: number; grossPerformancePercentage?: number;

View File

@ -327,6 +327,7 @@
hasPermissionToOpenDetails && hasPermissionToOpenDetails &&
!row.isDraft && !row.isDraft &&
onOpenPositionDialog({ onOpenPositionDialog({
dataSource: row.dataSource,
symbol: row.symbol symbol: row.symbol
}) })
" "

View File

@ -22,6 +22,7 @@ import { Router } from '@angular/router';
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config'; import { DEFAULT_DATE_FORMAT } from '@ghostfolio/common/config';
import { OrderWithAccount } from '@ghostfolio/common/types'; import { OrderWithAccount } from '@ghostfolio/common/types';
import { DataSource } from '@prisma/client';
import Big from 'big.js'; import Big from 'big.js';
import { endOfToday, format, isAfter } from 'date-fns'; import { endOfToday, format, isAfter } from 'date-fns';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
@ -190,9 +191,15 @@ export class ActivitiesTableComponent implements OnChanges, OnDestroy {
this.import.emit(); this.import.emit();
} }
public onOpenPositionDialog({ symbol }: { symbol: string }): void { public onOpenPositionDialog({
dataSource,
symbol
}: {
dataSource: DataSource;
symbol: string;
}): void {
this.router.navigate([], { this.router.navigate([], {
queryParams: { positionDetailDialog: true, symbol } queryParams: { dataSource, symbol, positionDetailDialog: true }
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "ghostfolio", "name": "ghostfolio",
"version": "1.108.0", "version": "1.111.0",
"homepage": "https://ghostfol.io", "homepage": "https://ghostfol.io",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"scripts": { "scripts": {
@ -14,6 +14,7 @@
"affected:test": "nx affected:test", "affected:test": "nx affected:test",
"angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng", "angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng",
"build:all": "ng build --configuration production api && ng build --configuration production client && yarn replace-placeholders-in-build", "build:all": "ng build --configuration production api && ng build --configuration production client && yarn replace-placeholders-in-build",
"build:dev": "nx build api && nx build client && yarn replace-placeholders-in-build",
"build:storybook": "nx run ui:build-storybook", "build:storybook": "nx run ui:build-storybook",
"clean": "rimraf dist", "clean": "rimraf dist",
"database:format-schema": "prisma format", "database:format-schema": "prisma format",

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Order" ALTER COLUMN "dataSource" DROP NOT NULL;

View File

@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Order" ALTER COLUMN "symbol" DROP NOT NULL;

View File

@ -0,0 +1,8 @@
-- DropForeignKey
ALTER TABLE "Order" DROP CONSTRAINT "Order_symbolProfileId_fkey";
-- AlterTable
ALTER TABLE "Order" ALTER COLUMN "symbolProfileId" SET NOT NULL;
-- AddForeignKey
ALTER TABLE "Order" ADD CONSTRAINT "Order_symbolProfileId_fkey" FOREIGN KEY ("symbolProfileId") REFERENCES "SymbolProfile"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@ -75,15 +75,15 @@ model Order {
accountUserId String? accountUserId String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
currency String? currency String?
dataSource DataSource dataSource DataSource?
date DateTime date DateTime
fee Float fee Float
id String @default(uuid()) id String @default(uuid())
isDraft Boolean @default(false) isDraft Boolean @default(false)
quantity Float quantity Float
symbol String symbol String?
SymbolProfile SymbolProfile? @relation(fields: [symbolProfileId], references: [id]) SymbolProfile SymbolProfile @relation(fields: [symbolProfileId], references: [id])
symbolProfileId String? symbolProfileId String
type Type type Type
unitPrice Float unitPrice Float
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt