diff --git a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts index f80633f87..cc92efa02 100644 --- a/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts +++ b/apps/api/src/app/endpoints/data-providers/ghostfolio/ghostfolio.service.ts @@ -56,11 +56,36 @@ export class GhostfolioService { requestTimeout, symbol }) - .then((assetProfile) => { + .then(async (assetProfile) => { + const dataSourceOrigin = DataSource.GHOSTFOLIO; + + if (assetProfile) { + await this.prismaService.assetProfileResolution.upsert({ + create: { + dataSourceOrigin, + currency: assetProfile.currency, + dataSourceTarget: assetProfile.dataSource, + symbolOrigin: symbol, + symbolTarget: assetProfile.symbol + }, + update: { + requestCount: { + increment: 1 + } + }, + where: { + dataSourceOrigin_symbolOrigin: { + dataSourceOrigin, + symbolOrigin: symbol + } + } + }); + } + result = { ...result, ...assetProfile, - dataSource: DataSource.GHOSTFOLIO + dataSource: dataSourceOrigin }; return assetProfile; diff --git a/apps/client/src/app/pages/api/api-page.component.ts b/apps/client/src/app/pages/api/api-page.component.ts index 87fc164af..353605380 100644 --- a/apps/client/src/app/pages/api/api-page.component.ts +++ b/apps/client/src/app/pages/api/api-page.component.ts @@ -4,6 +4,7 @@ import { } from '@ghostfolio/common/config'; import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { + DataProviderGhostfolioAssetProfileResponse, DataProviderGhostfolioStatusResponse, DividendsResponse, HistoricalResponse, @@ -25,6 +26,7 @@ import { map, Observable, Subject, takeUntil } from 'rxjs'; templateUrl: './api-page.html' }) export class GfApiPageComponent implements OnInit { + public assetProfile$: Observable; public dividends$: Observable; public historicalData$: Observable; public isinLookupItems$: Observable; @@ -40,6 +42,7 @@ export class GfApiPageComponent implements OnInit { public ngOnInit() { this.apiKey = prompt($localize`Please enter your Ghostfolio API key:`); + this.assetProfile$ = this.fetchAssetProfile({ symbol: 'AAPL' }); this.dividends$ = this.fetchDividends({ symbol: 'KO' }); this.historicalData$ = this.fetchHistoricalData({ symbol: 'AAPL' }); this.isinLookupItems$ = this.fetchLookupItems({ query: 'US0378331005' }); @@ -53,6 +56,15 @@ export class GfApiPageComponent implements OnInit { this.unsubscribeSubject.complete(); } + private fetchAssetProfile({ symbol }: { symbol: string }) { + return this.http + .get( + `/api/v1/data-providers/ghostfolio/asset-profile/${symbol}`, + { headers: this.getHeaders() } + ) + .pipe(takeUntil(this.unsubscribeSubject)); + } + private fetchDividends({ symbol }: { symbol: string }) { const params = new HttpParams() .set('from', format(startOfYear(new Date()), DATE_FORMAT)) diff --git a/apps/client/src/app/pages/api/api-page.html b/apps/client/src/app/pages/api/api-page.html index d8bfc75d7..3c43484e6 100644 --- a/apps/client/src/app/pages/api/api-page.html +++ b/apps/client/src/app/pages/api/api-page.html @@ -3,6 +3,10 @@

Status

{{ status$ | async | json }}
+
+

Asset Profile

+
{{ assetProfile$ | async | json }}
+

Lookup

@if (lookupItems$) { diff --git a/prisma/migrations/20250915163323_added_asset_profile_resolution/migration.sql b/prisma/migrations/20250915163323_added_asset_profile_resolution/migration.sql new file mode 100644 index 000000000..947c1f186 --- /dev/null +++ b/prisma/migrations/20250915163323_added_asset_profile_resolution/migration.sql @@ -0,0 +1,17 @@ +-- CreateTable +CREATE TABLE "public"."AssetProfileResolution" ( + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "currency" TEXT NOT NULL, + "dataSourceOrigin" "public"."DataSource" NOT NULL, + "dataSourceTarget" "public"."DataSource" NOT NULL, + "id" TEXT NOT NULL, + "requestCount" INTEGER NOT NULL DEFAULT 1, + "symbolOrigin" TEXT NOT NULL, + "symbolTarget" TEXT NOT NULL, + "updatedAt" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "AssetProfileResolution_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "AssetProfileResolution_dataSourceOrigin_symbolOrigin_key" ON "public"."AssetProfileResolution"("dataSourceOrigin", "symbolOrigin"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 609bede5c..67ca81682 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -88,6 +88,20 @@ model ApiKey { @@index([userId]) } +model AssetProfileResolution { + createdAt DateTime @default(now()) + currency String + dataSourceOrigin DataSource + dataSourceTarget DataSource + id String @id @default(uuid()) + requestCount Int @default(1) + symbolOrigin String + symbolTarget String + updatedAt DateTime @updatedAt + + @@unique([dataSourceOrigin, symbolOrigin]) +} + model AuthDevice { createdAt DateTime @default(now()) credentialId Bytes