Browse Source
Task/reuse asset profile identifier (part 2) (#7087)
Reuse AssetProfileIdentifier
pull/7084/head
Thomas Kaul
1 week ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with
23 additions and
54 deletions
-
apps/api/src/app/endpoints/watchlist/watchlist.service.ts
-
apps/api/src/app/portfolio/portfolio.service.spec.ts
-
apps/api/src/app/portfolio/portfolio.service.ts
-
apps/api/src/events/asset-profile-changed.listener.ts
-
apps/api/src/services/data-provider/data-provider.service.ts
-
apps/api/src/services/queues/data-gathering/data-gathering.service.ts
-
libs/common/src/lib/interfaces/responses/export-response.interface.ts
-
libs/ui/src/lib/services/admin.service.ts
-
libs/ui/src/lib/services/data.service.ts
|
|
|
@ -5,10 +5,13 @@ import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
|
import { DataGatheringService } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.service'; |
|
|
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; |
|
|
|
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper'; |
|
|
|
import { WatchlistResponse } from '@ghostfolio/common/interfaces'; |
|
|
|
import { |
|
|
|
AssetProfileIdentifier, |
|
|
|
WatchlistResponse |
|
|
|
} from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
|
|
import { BadRequestException, Injectable } from '@nestjs/common'; |
|
|
|
import { DataSource, Prisma } from '@prisma/client'; |
|
|
|
import { Prisma } from '@prisma/client'; |
|
|
|
|
|
|
|
@Injectable() |
|
|
|
export class WatchlistService { |
|
|
|
@ -25,11 +28,7 @@ export class WatchlistService { |
|
|
|
dataSource, |
|
|
|
symbol, |
|
|
|
userId |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
symbol: string; |
|
|
|
userId: string; |
|
|
|
}): Promise<void> { |
|
|
|
}: { userId: string } & AssetProfileIdentifier): Promise<void> { |
|
|
|
const symbolProfile = await this.prismaService.symbolProfile.findUnique({ |
|
|
|
where: { |
|
|
|
dataSource_symbol: { dataSource, symbol } |
|
|
|
@ -73,11 +72,7 @@ export class WatchlistService { |
|
|
|
dataSource, |
|
|
|
symbol, |
|
|
|
userId |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
symbol: string; |
|
|
|
userId: string; |
|
|
|
}) { |
|
|
|
}: { userId: string } & AssetProfileIdentifier) { |
|
|
|
await this.prismaService.user.update({ |
|
|
|
data: { |
|
|
|
watchlist: { |
|
|
|
|
|
|
|
@ -11,6 +11,7 @@ import { ImpersonationService } from '@ghostfolio/api/services/impersonation/imp |
|
|
|
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; |
|
|
|
import { UNKNOWN_KEY } from '@ghostfolio/common/config'; |
|
|
|
import { parseDate } from '@ghostfolio/common/helper'; |
|
|
|
import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
|
|
import { Account, DataSource } from '@prisma/client'; |
|
|
|
import { Big } from 'big.js'; |
|
|
|
@ -198,7 +199,7 @@ describe('PortfolioService', () => { |
|
|
|
portfolioService as unknown as { |
|
|
|
getCashSymbolProfiles: ( |
|
|
|
aCashDetails: CashDetails |
|
|
|
) => { dataSource: DataSource; symbol: string }[]; |
|
|
|
) => AssetProfileIdentifier[]; |
|
|
|
} |
|
|
|
).getCashSymbolProfiles(cashDetails); |
|
|
|
|
|
|
|
|
|
|
|
@ -46,6 +46,7 @@ import { |
|
|
|
import { |
|
|
|
AccountsResponse, |
|
|
|
Activity, |
|
|
|
AssetProfileIdentifier, |
|
|
|
EnhancedSymbolProfile, |
|
|
|
Filter, |
|
|
|
HistoricalDataItem, |
|
|
|
@ -776,11 +777,9 @@ export class PortfolioService { |
|
|
|
symbol, |
|
|
|
userId |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
impersonationId: string; |
|
|
|
symbol: string; |
|
|
|
userId: string; |
|
|
|
}): Promise<PortfolioHoldingResponse> { |
|
|
|
} & AssetProfileIdentifier): Promise<PortfolioHoldingResponse> { |
|
|
|
userId = await this.getUserId(impersonationId, userId); |
|
|
|
const user = await this.userService.user({ id: userId }); |
|
|
|
const userCurrency = this.getUserCurrency(user); |
|
|
|
@ -1381,12 +1380,10 @@ export class PortfolioService { |
|
|
|
tags, |
|
|
|
userId |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
impersonationId: string; |
|
|
|
symbol: string; |
|
|
|
tags: Tag[]; |
|
|
|
userId: string; |
|
|
|
}) { |
|
|
|
} & AssetProfileIdentifier) { |
|
|
|
userId = await this.getUserId(impersonationId, userId); |
|
|
|
|
|
|
|
await this.activitiesService.assignTags({ |
|
|
|
|
|
|
|
@ -5,10 +5,10 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate- |
|
|
|
import { DataGatheringService } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.service'; |
|
|
|
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config'; |
|
|
|
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper'; |
|
|
|
import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces'; |
|
|
|
|
|
|
|
import { Injectable, Logger } from '@nestjs/common'; |
|
|
|
import { OnEvent } from '@nestjs/event-emitter'; |
|
|
|
import { DataSource } from '@prisma/client'; |
|
|
|
import ms from 'ms'; |
|
|
|
|
|
|
|
import { AssetProfileChangedEvent } from './asset-profile-changed.event'; |
|
|
|
@ -64,11 +64,7 @@ export class AssetProfileChangedListener { |
|
|
|
currency, |
|
|
|
dataSource, |
|
|
|
symbol |
|
|
|
}: { |
|
|
|
currency: string; |
|
|
|
dataSource: DataSource; |
|
|
|
symbol: string; |
|
|
|
}) { |
|
|
|
}: { currency: string } & AssetProfileIdentifier) { |
|
|
|
this.logger.log(`Asset profile of ${symbol} (${dataSource}) has changed`); |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
@ -320,12 +320,10 @@ export class DataProviderService implements OnModuleInit { |
|
|
|
symbol, |
|
|
|
to |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
from: Date; |
|
|
|
granularity: Granularity; |
|
|
|
symbol: string; |
|
|
|
to: Date; |
|
|
|
}) { |
|
|
|
} & AssetProfileIdentifier) { |
|
|
|
return this.getDataProvider(DataSource[dataSource]).getDividends({ |
|
|
|
from, |
|
|
|
granularity, |
|
|
|
|
|
|
|
@ -28,7 +28,7 @@ import { |
|
|
|
|
|
|
|
import { InjectQueue } from '@nestjs/bull'; |
|
|
|
import { Inject, Injectable, Logger } from '@nestjs/common'; |
|
|
|
import { DataSource, Prisma } from '@prisma/client'; |
|
|
|
import { Prisma } from '@prisma/client'; |
|
|
|
import { JobOptions, Queue } from 'bull'; |
|
|
|
import { format, min, subDays, subMilliseconds, subYears } from 'date-fns'; |
|
|
|
import { isEmpty } from 'lodash'; |
|
|
|
@ -122,11 +122,7 @@ export class DataGatheringService { |
|
|
|
dataSource, |
|
|
|
date, |
|
|
|
symbol |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
date: Date; |
|
|
|
symbol: string; |
|
|
|
}) { |
|
|
|
}: { date: Date } & AssetProfileIdentifier) { |
|
|
|
try { |
|
|
|
const historicalData = await this.dataProviderService.getHistoricalRaw({ |
|
|
|
assetProfileIdentifiers: [{ dataSource, symbol }], |
|
|
|
|
|
|
|
@ -1,13 +1,7 @@ |
|
|
|
import { |
|
|
|
Account, |
|
|
|
DataSource, |
|
|
|
Order, |
|
|
|
Platform, |
|
|
|
SymbolProfile, |
|
|
|
Tag |
|
|
|
} from '@prisma/client'; |
|
|
|
import { Account, Order, Platform, SymbolProfile, Tag } from '@prisma/client'; |
|
|
|
|
|
|
|
import { AccountBalance } from '../account-balance.interface'; |
|
|
|
import { AssetProfileIdentifier } from '../asset-profile-identifier.interface'; |
|
|
|
import { MarketData } from '../market-data.interface'; |
|
|
|
import { UserSettings } from '../user-settings.interface'; |
|
|
|
|
|
|
|
@ -24,7 +18,7 @@ export interface ExportResponse { |
|
|
|
| 'symbolProfileId' |
|
|
|
| 'updatedAt' |
|
|
|
| 'userId' |
|
|
|
> & { dataSource: DataSource; date: string; symbol: string })[]; |
|
|
|
> & { date: string } & AssetProfileIdentifier)[]; |
|
|
|
assetProfiles: (Omit< |
|
|
|
SymbolProfile, |
|
|
|
| 'createdAt' |
|
|
|
|
|
|
|
@ -23,7 +23,7 @@ import { GF_ENVIRONMENT } from '@ghostfolio/ui/environment'; |
|
|
|
|
|
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; |
|
|
|
import { Injectable, inject } from '@angular/core'; |
|
|
|
import { DataSource, MarketData, Platform } from '@prisma/client'; |
|
|
|
import { MarketData, Platform } from '@prisma/client'; |
|
|
|
import { JobStatus } from 'bull'; |
|
|
|
import { isNumber } from 'lodash'; |
|
|
|
|
|
|
|
@ -171,11 +171,7 @@ export class AdminService { |
|
|
|
dataSource, |
|
|
|
dateString, |
|
|
|
symbol |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
dateString: string; |
|
|
|
symbol: string; |
|
|
|
}) { |
|
|
|
}: { dateString: string } & AssetProfileIdentifier) { |
|
|
|
const url = `/api/v1/symbol/${dataSource}/${symbol}/${dateString}`; |
|
|
|
|
|
|
|
return this.http.get<DataProviderHistoricalResponse>(url); |
|
|
|
|
|
|
|
@ -850,11 +850,7 @@ export class DataService { |
|
|
|
dataSource, |
|
|
|
marketData, |
|
|
|
symbol |
|
|
|
}: { |
|
|
|
dataSource: DataSource; |
|
|
|
marketData: UpdateBulkMarketDataDto; |
|
|
|
symbol: string; |
|
|
|
}) { |
|
|
|
}: { marketData: UpdateBulkMarketDataDto } & AssetProfileIdentifier) { |
|
|
|
const url = `/api/v1/market-data/${dataSource}/${symbol}`; |
|
|
|
|
|
|
|
return this.http.post<MarketData>(url, marketData); |
|
|
|
|