mirror of https://github.com/ghostfolio/ghostfolio
3 changed files with 79 additions and 4 deletions
@ -1,15 +1,30 @@ |
|||||
|
import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; |
||||
|
import { CryptocurrencyModule } from '@ghostfolio/api/services/cryptocurrency/cryptocurrency.module'; |
||||
import { TrackinsightDataEnhancerService } from '@ghostfolio/api/services/data-provider/data-enhancer/trackinsight/trackinsight.service'; |
import { TrackinsightDataEnhancerService } from '@ghostfolio/api/services/data-provider/data-enhancer/trackinsight/trackinsight.service'; |
||||
|
import { YahooFinanceDataEnhancerService } from '@ghostfolio/api/services/data-provider/data-enhancer/yahoo-finance/yahoo-finance.service'; |
||||
|
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; |
||||
|
import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; |
||||
import { Module } from '@nestjs/common'; |
import { Module } from '@nestjs/common'; |
||||
|
|
||||
@Module({ |
@Module({ |
||||
exports: ['DataEnhancers', TrackinsightDataEnhancerService], |
exports: [ |
||||
|
'DataEnhancers', |
||||
|
TrackinsightDataEnhancerService, |
||||
|
YahooFinanceDataEnhancerService |
||||
|
], |
||||
|
imports: [ConfigurationModule, CryptocurrencyModule, DataProviderModule], |
||||
providers: [ |
providers: [ |
||||
|
TrackinsightDataEnhancerService, |
||||
|
YahooFinanceDataEnhancerService, |
||||
{ |
{ |
||||
inject: [TrackinsightDataEnhancerService], |
inject: [ |
||||
|
TrackinsightDataEnhancerService, |
||||
|
YahooFinanceDataEnhancerService |
||||
|
], |
||||
provide: 'DataEnhancers', |
provide: 'DataEnhancers', |
||||
useFactory: (trackinsight) => [trackinsight] |
useFactory: (trackinsight, yahooFinance) => [trackinsight, yahooFinance] |
||||
}, |
}, |
||||
TrackinsightDataEnhancerService |
YahooFinanceService |
||||
] |
] |
||||
}) |
}) |
||||
export class DataEnhancerModule {} |
export class DataEnhancerModule {} |
||||
|
@ -0,0 +1,58 @@ |
|||||
|
import { DataEnhancerInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-enhancer.interface'; |
||||
|
import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; |
||||
|
import { Injectable, Logger } from '@nestjs/common'; |
||||
|
import { DataSource, SymbolProfile } from '@prisma/client'; |
||||
|
|
||||
|
@Injectable() |
||||
|
export class YahooFinanceDataEnhancerService implements DataEnhancerInterface { |
||||
|
public constructor( |
||||
|
private readonly yahooFinanceService: YahooFinanceService |
||||
|
) {} |
||||
|
|
||||
|
public async enhance({ |
||||
|
response, |
||||
|
symbol |
||||
|
}: { |
||||
|
response: Partial<SymbolProfile>; |
||||
|
symbol: string; |
||||
|
}): Promise<Partial<SymbolProfile>> { |
||||
|
if (response.dataSource !== 'YAHOO' && !response.isin) { |
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
try { |
||||
|
let yahooSymbol: string; |
||||
|
|
||||
|
if (response.dataSource === 'YAHOO') { |
||||
|
yahooSymbol = symbol; |
||||
|
} else { |
||||
|
const { items } = await this.yahooFinanceService.search(response.isin); |
||||
|
yahooSymbol = items[0].symbol; |
||||
|
} |
||||
|
|
||||
|
const assetProfile = await this.yahooFinanceService.getAssetProfile( |
||||
|
yahooSymbol |
||||
|
); |
||||
|
|
||||
|
if (assetProfile.countries) { |
||||
|
response.countries = assetProfile.countries; |
||||
|
} |
||||
|
|
||||
|
if (assetProfile.sectors) { |
||||
|
response.sectors = assetProfile.sectors; |
||||
|
} |
||||
|
|
||||
|
if (assetProfile.url) { |
||||
|
response.url = assetProfile.url; |
||||
|
} |
||||
|
} catch (error) { |
||||
|
Logger.error(error, 'YahooFinanceDataEnhancerService'); |
||||
|
} |
||||
|
|
||||
|
return response; |
||||
|
} |
||||
|
|
||||
|
public getName() { |
||||
|
return DataSource.YAHOO; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue