Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/set up asset profile resolution database table (#5533)

Thomas Kaul40f5c93f43dc
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 f80633f872..cc92efa028 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 87fc164af2..3536053807 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<DataProviderGhostfolioAssetProfileResponse>;
public dividends$: Observable<DividendsResponse['dividends']>;
public historicalData$: Observable<HistoricalResponse['historicalData']>;
public isinLookupItems$: Observable<LookupResponse['items']>;
@@ -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<DataProviderGhostfolioAssetProfileResponse>(
+ `/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 d8bfc75d72..3c43484e60 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 @@
<h2 class="text-center">Status</h2>
<div>{{ status$ | async | json }}</div>
</div>
+ <div class="mb-3">
+ <h2 class="text-center">Asset Profile</h2>
+ <div>{{ assetProfile$ | async | json }}</div>
+ </div>
<div>
<h2 class="text-center">Lookup</h2>
@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 0000000000..947c1f1868
--- /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 609bede5c9..67ca81682f 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