Browse Source

Deactivate asset profile on delisting

pull/4524/head
csehatt741 5 days ago
parent
commit
15dc953bc7
  1. 1
      CHANGELOG.md
  2. 6
      apps/api/src/services/data-provider/yahoo-finance/asset-profile-delisted.error.ts
  3. 18
      apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts
  4. 24
      apps/api/src/services/queues/data-gathering/data-gathering.processor.ts

1
CHANGELOG.md

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added the data gathering status column to the historical market data table of the admin control
- Deactivated asset profiles that has been delisted by Yahoo Finance
### Changed

6
apps/api/src/services/data-provider/yahoo-finance/asset-profile-delisted.error.ts

@ -0,0 +1,6 @@
export class AssetProfileDelistedError extends Error {
constructor(message: string) {
super(message);
this.name = 'AssetProfileDelistedError';
}
}

18
apps/api/src/services/data-provider/yahoo-finance/yahoo-finance.service.ts

@ -31,6 +31,8 @@ import {
} from 'yahoo-finance2/dist/esm/src/modules/historical';
import { Quote } from 'yahoo-finance2/dist/esm/src/modules/quote';
import { AssetProfileDelistedError } from './asset-profile-delisted.error';
@Injectable()
export class YahooFinanceService implements DataProviderInterface {
public constructor(
@ -143,12 +145,16 @@ export class YahooFinanceService implements DataProviderInterface {
return response;
} catch (error) {
throw new Error(
`Could not get historical market data for ${symbol} (${this.getName()}) from ${format(
from,
DATE_FORMAT
)} to ${format(to, DATE_FORMAT)}: [${error.name}] ${error.message}`
);
if (error.message === 'No data found, symbol may be delisted') {
throw new AssetProfileDelistedError(error.message);
} else {
throw new Error(
`Could not get historical market data for ${symbol} (${this.getName()}) from ${format(
from,
DATE_FORMAT
)} to ${format(to, DATE_FORMAT)}: [${error.name}] ${error.message}`
);
}
}
}

24
apps/api/src/services/queues/data-gathering/data-gathering.processor.ts

@ -1,6 +1,8 @@
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
import { AssetProfileDelistedError } from '@ghostfolio/api/services/data-provider/yahoo-finance/asset-profile-delisted.error';
import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces';
import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service';
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service';
import {
DATA_GATHERING_QUEUE,
DEFAULT_PROCESSOR_GATHER_ASSET_PROFILE_CONCURRENCY,
@ -33,7 +35,8 @@ export class DataGatheringProcessor {
public constructor(
private readonly dataGatheringService: DataGatheringService,
private readonly dataProviderService: DataProviderService,
private readonly marketDataService: MarketDataService
private readonly marketDataService: MarketDataService,
private readonly symbolProfileService: SymbolProfileService
) {}
@Process({
@ -76,8 +79,9 @@ export class DataGatheringProcessor {
name: GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_NAME
})
public async gatherHistoricalMarketData(job: Job<IDataGatheringItem>) {
const { dataSource, date, symbol } = job.data;
try {
const { dataSource, date, symbol } = job.data;
let currentDate = parseISO(date as unknown as string);
Logger.log(
@ -142,12 +146,26 @@ export class DataGatheringProcessor {
`DataGatheringProcessor (${GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_NAME})`
);
} catch (error) {
if (error instanceof AssetProfileDelistedError) {
const updatedSymbolProfile: Prisma.SymbolProfileUpdateInput = {
isActive: false
};
await this.symbolProfileService.updateSymbolProfile(
{
dataSource,
symbol
},
updatedSymbolProfile
);
}
Logger.error(
error,
`DataGatheringProcessor (${GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_NAME})`
);
throw new Error(error);
throw error;
}
}
}

Loading…
Cancel
Save