Browse Source

Fix symbol mapping for manual assets

pull/7145/head
Alexander Linder 3 weeks ago
parent
commit
0fdc209da5
Failed to extract signature
  1. 48
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts

48
apps/api/src/services/queues/data-gathering/data-gathering.service.ts

@ -72,11 +72,7 @@ export class DataGatheringService {
public async gatherAssetProfiles( public async gatherAssetProfiles(
aAssetProfileIdentifiers?: AssetProfileIdentifier[] aAssetProfileIdentifiers?: AssetProfileIdentifier[]
) { ) {
let assetProfileIdentifiers = aAssetProfileIdentifiers?.filter( let assetProfileIdentifiers = aAssetProfileIdentifiers;
(dataGatheringItem) => {
return dataGatheringItem.dataSource !== 'MANUAL';
}
);
if (!assetProfileIdentifiers) { if (!assetProfileIdentifiers) {
assetProfileIdentifiers = await this.getActiveAssetProfileIdentifiers(); assetProfileIdentifiers = await this.getActiveAssetProfileIdentifiers();
@ -86,10 +82,31 @@ export class DataGatheringService {
return; return;
} }
const assetProfiles = await this.dataProviderService.getAssetProfiles( const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
assetProfileIdentifiers assetProfileIdentifiers
); );
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
// Exclude MANUAL asset profiles unless they define a symbol mapping that
// lets data enhancers gather profile data from another data source
assetProfileIdentifiers = assetProfileIdentifiers.filter(
({ dataSource, symbol }) => {
if (dataSource !== 'MANUAL') {
return true;
}
const symbolProfile = symbolProfiles.find((profile) => {
return profile.dataSource === dataSource && profile.symbol === symbol;
});
return !isEmpty(symbolProfile?.symbolMapping);
}
);
if (assetProfileIdentifiers.length <= 0) {
return;
}
const assetProfiles = await this.dataProviderService.getAssetProfiles(
assetProfileIdentifiers assetProfileIdentifiers
); );
@ -372,15 +389,16 @@ export class DataGatheringService {
}: { }: {
maxAge?: StringValue; maxAge?: StringValue;
} = {}): Promise<AssetProfileIdentifier[]> { } = {}): Promise<AssetProfileIdentifier[]> {
return this.prismaService.symbolProfile.findMany({ const symbolProfiles = await this.prismaService.symbolProfile.findMany({
orderBy: [{ symbol: 'asc' }, { dataSource: 'asc' }], orderBy: [{ symbol: 'asc' }, { dataSource: 'asc' }],
select: { select: {
dataSource: true, dataSource: true,
symbol: true symbol: true,
symbolMapping: true
}, },
where: { where: {
dataSource: { dataSource: {
notIn: ['MANUAL', 'RAPID_API'] not: 'RAPID_API'
}, },
isActive: true, isActive: true,
...(maxAge && { ...(maxAge && {
@ -390,6 +408,16 @@ export class DataGatheringService {
}) })
} }
}); });
return symbolProfiles
.filter(({ dataSource, symbolMapping }) => {
// Include MANUAL asset profiles only when they define a symbol mapping
// that lets data enhancers gather profile data from another data source
return dataSource !== 'MANUAL' || !isEmpty(symbolMapping);
})
.map(({ dataSource, symbol }) => {
return { dataSource, symbol };
});
} }
private async getAssetProfileIdentifiersWithCompleteMarketData(): Promise< private async getAssetProfileIdentifiersWithCompleteMarketData(): Promise<

Loading…
Cancel
Save