Browse Source

Add symbol mapping

pull/452/head
Thomas 4 years ago
parent
commit
49d865e602
  1. 4
      apps/api/src/app/cache/cache.module.ts
  2. 4
      apps/api/src/app/info/info.module.ts
  3. 6
      apps/api/src/app/portfolio/portfolio.module.ts
  4. 4
      apps/api/src/services/data-gathering.module.ts
  5. 16
      apps/api/src/services/data-gathering.service.ts
  6. 4
      apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts
  7. 2
      apps/api/src/services/data-provider/interfaces/data-enhancer.interface.ts
  8. 5
      apps/api/src/services/interfaces/symbol-profile.interface.ts
  9. 11
      apps/api/src/services/symbol-profile.module.ts
  10. 12
      apps/api/src/services/symbol-profile.service.ts
  11. 1
      prisma/schema.prisma

4
apps/api/src/app/cache/cache.module.ts

@ -6,6 +6,7 @@ import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.se
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module';
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile.module';
import { Module } from '@nestjs/common';
import { CacheController } from './cache.controller';
@ -15,7 +16,8 @@ import { CacheController } from './cache.controller';
DataGatheringModule,
DataProviderModule,
ExchangeRateDataModule,
RedisCacheModule
RedisCacheModule,
SymbolProfileModule
],
controllers: [CacheController],
providers: [

4
apps/api/src/app/info/info.module.ts

@ -4,6 +4,7 @@ import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.se
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module';
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile.module';
import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
@ -18,7 +19,8 @@ import { InfoService } from './info.service';
JwtModule.register({
secret: process.env.JWT_SECRET_KEY,
signOptions: { expiresIn: '30 days' }
})
}),
SymbolProfileModule
],
controllers: [InfoController],
providers: [

6
apps/api/src/app/portfolio/portfolio.module.ts

@ -8,7 +8,7 @@ import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-
import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module';
import { ImpersonationModule } from '@ghostfolio/api/services/impersonation.module';
import { PrismaModule } from '@ghostfolio/api/services/prisma.module';
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service';
import { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile.module';
import { Module } from '@nestjs/common';
import { CurrentRateService } from './current-rate.service';
@ -27,6 +27,7 @@ import { RulesService } from './rules.service';
ImpersonationModule,
OrderModule,
PrismaModule,
SymbolProfileModule,
UserModule
],
controllers: [PortfolioController],
@ -35,8 +36,7 @@ import { RulesService } from './rules.service';
CurrentRateService,
MarketDataService,
PortfolioService,
RulesService,
SymbolProfileService
RulesService
]
})
export class PortfolioModule {}

4
apps/api/src/services/data-gathering.module.ts

@ -6,6 +6,7 @@ import { PrismaModule } from '@ghostfolio/api/services/prisma.module';
import { Module } from '@nestjs/common';
import { ExchangeRateDataModule } from './exchange-rate-data.module';
import { SymbolProfileModule } from './symbol-profile.module';
@Module({
imports: [
@ -13,7 +14,8 @@ import { ExchangeRateDataModule } from './exchange-rate-data.module';
DataEnhancerModule,
DataProviderModule,
ExchangeRateDataModule,
PrismaModule
PrismaModule,
SymbolProfileModule
],
providers: [DataGatheringService],
exports: [DataEnhancerModule, DataGatheringService]

16
apps/api/src/services/data-gathering.service.ts

@ -1,3 +1,4 @@
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service';
import {
benchmarks,
ghostfolioFearAndGreedIndexSymbol
@ -32,7 +33,8 @@ export class DataGatheringService {
private readonly dataProviderService: DataProviderService,
private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly ghostfolioScraperApi: GhostfolioScraperApiService,
private readonly prismaService: PrismaService
private readonly prismaService: PrismaService,
private readonly symbolProfileService: SymbolProfileService
) {}
public async gather7Days() {
@ -132,13 +134,23 @@ export class DataGatheringService {
}
const currentData = await this.dataProviderService.get(dataGatheringItems);
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
dataGatheringItems.map(({ symbol }) => {
return symbol;
})
);
for (const [symbol, response] of Object.entries(currentData)) {
const symbolMapping =
symbolProfiles.find((symbolProfile) => {
return symbolProfile.symbol === symbol;
})?.settings?.symbolMapping ?? {};
for (const dataEnhancer of this.dataEnhancers) {
try {
currentData[symbol] = await dataEnhancer.enhance({
response,
symbol
symbol: symbolMapping[dataEnhancer.getName()] ?? symbol
});
} catch (error) {
console.error(`Failed to enhance data for symbol ${symbol}`, error);

4
apps/api/src/services/data-provider/data-enhancer/trackinsight/trackinsight.service.ts

@ -70,4 +70,8 @@ export class TrackinsightDataEnhancerService implements DataEnhancerInterface {
return Promise.resolve(response);
}
public getName() {
return 'TRACKINSIGHT';
}
}

2
apps/api/src/services/data-provider/interfaces/data-enhancer.interface.ts

@ -8,4 +8,6 @@ export interface DataEnhancerInterface {
response: IDataProviderResponse;
symbol: string;
}): Promise<IDataProviderResponse>;
getName(): string;
}

5
apps/api/src/services/interfaces/symbol-profile.interface.ts

@ -11,7 +11,12 @@ export interface EnhancedSymbolProfile {
id: string;
name: string | null;
updatedAt: Date;
settings?: SymbolProfileSettings;
symbol: string;
countries: Country[];
sectors: Sector[];
}
export interface SymbolProfileSettings {
symbolMapping: { [key: string]: string };
}

11
apps/api/src/services/symbol-profile.module.ts

@ -0,0 +1,11 @@
import { PrismaModule } from '@ghostfolio/api/services/prisma.module';
import { Module } from '@nestjs/common';
import { SymbolProfileService } from './symbol-profile.service';
@Module({
imports: [PrismaModule],
providers: [SymbolProfileService],
exports: [SymbolProfileService]
})
export class SymbolProfileModule {}

12
apps/api/src/services/symbol-profile.service.ts

@ -1,4 +1,7 @@
import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface';
import {
EnhancedSymbolProfile,
SymbolProfileSettings
} from '@ghostfolio/api/services/interfaces/symbol-profile.interface';
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { UNKNOWN_KEY } from '@ghostfolio/common/config';
import { Country } from '@ghostfolio/common/interfaces/country.interface';
@ -29,7 +32,8 @@ export class SymbolProfileService {
return symbolProfiles.map((symbolProfile) => ({
...symbolProfile,
countries: this.getCountries(symbolProfile),
sectors: this.getSectors(symbolProfile)
sectors: this.getSectors(symbolProfile),
settings: this.getSettings(symbolProfile)
}));
}
@ -61,4 +65,8 @@ export class SymbolProfileService {
}
);
}
private getSettings(symbolProfile: SymbolProfile): SymbolProfileSettings {
return { symbolMapping: symbolProfile.settings['symbolMapping'] };
}
}

1
prisma/schema.prisma

@ -127,6 +127,7 @@ model SymbolProfile {
id String @id @default(uuid())
name String?
Order Order[]
settings Json?
updatedAt DateTime @updatedAt
sectors Json?
symbol String

Loading…
Cancel
Save