Feature/eliminate name from scraper config (#277)
* Eliminate name from scraper config * Update changelog
This commit is contained in:
parent
0a85a56c67
commit
8ac1272a9d
@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
- Improved the data gathering handling on server restart
|
- Improved the data gathering handling on server restart
|
||||||
- Respected the cash balance on the allocations page
|
- Respected the cash balance on the allocations page
|
||||||
|
- Eliminated the name from the scraper configuration
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { DataProviderService } from '@ghostfolio/api/services/data-provider.service';
|
import { DataProviderService } from '@ghostfolio/api/services/data-provider.service';
|
||||||
import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service';
|
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
||||||
import { convertFromYahooSymbol } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Currency, DataSource } from '@prisma/client';
|
import { Currency, DataSource } from '@prisma/client';
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ import { SymbolItem } from './interfaces/symbol-item.interface';
|
|||||||
export class SymbolService {
|
export class SymbolService {
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly dataProviderService: DataProviderService,
|
private readonly dataProviderService: DataProviderService,
|
||||||
private readonly ghostfolioScraperApiService: GhostfolioScraperApiService
|
private readonly prismaService: PrismaService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async get(aSymbol: string): Promise<SymbolItem> {
|
public async get(aSymbol: string): Promise<SymbolItem> {
|
||||||
@ -37,16 +36,28 @@ export class SymbolService {
|
|||||||
results.items = items;
|
results.items = items;
|
||||||
|
|
||||||
// Add custom symbols
|
// Add custom symbols
|
||||||
const scraperConfigurations = await this.ghostfolioScraperApiService.getScraperConfigurations();
|
const ghostfolioSymbolProfiles =
|
||||||
scraperConfigurations.forEach((scraperConfiguration) => {
|
await this.prismaService.symbolProfile.findMany({
|
||||||
if (scraperConfiguration.name.toLowerCase().startsWith(aQuery)) {
|
select: {
|
||||||
results.items.push({
|
dataSource: true,
|
||||||
dataSource: DataSource.GHOSTFOLIO,
|
name: true,
|
||||||
name: scraperConfiguration.name,
|
symbol: true
|
||||||
symbol: scraperConfiguration.symbol
|
},
|
||||||
});
|
where: {
|
||||||
}
|
AND: [
|
||||||
});
|
{
|
||||||
|
dataSource: DataSource.GHOSTFOLIO,
|
||||||
|
name: {
|
||||||
|
startsWith: aQuery
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const ghostfolioSymbolProfile of ghostfolioSymbolProfiles) {
|
||||||
|
results.items.push(ghostfolioSymbolProfile);
|
||||||
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -333,9 +333,8 @@ export class DataGatheringService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const customSymbolsToGather = await this.getCustomSymbolsToGather(
|
const customSymbolsToGather =
|
||||||
startDate
|
await this.ghostfolioScraperApi.getCustomSymbolsToGather(startDate);
|
||||||
);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
...this.getBenchmarksToGather(startDate),
|
...this.getBenchmarksToGather(startDate),
|
||||||
@ -348,9 +347,8 @@ export class DataGatheringService {
|
|||||||
private async getSymbolsMax(): Promise<IDataGatheringItem[]> {
|
private async getSymbolsMax(): Promise<IDataGatheringItem[]> {
|
||||||
const startDate = new Date(getUtc('2015-01-01'));
|
const startDate = new Date(getUtc('2015-01-01'));
|
||||||
|
|
||||||
const customSymbolsToGather = await this.getCustomSymbolsToGather(
|
const customSymbolsToGather =
|
||||||
startDate
|
await this.ghostfolioScraperApi.getCustomSymbolsToGather(startDate);
|
||||||
);
|
|
||||||
|
|
||||||
const currencyPairsToGather = currencyPairs.map(
|
const currencyPairsToGather = currencyPairs.map(
|
||||||
({ dataSource, symbol }) => {
|
({ dataSource, symbol }) => {
|
||||||
|
@ -12,6 +12,7 @@ import { format } from 'date-fns';
|
|||||||
|
|
||||||
import { DataProviderInterface } from '../../interfaces/data-provider.interface';
|
import { DataProviderInterface } from '../../interfaces/data-provider.interface';
|
||||||
import {
|
import {
|
||||||
|
IDataGatheringItem,
|
||||||
IDataProviderHistoricalResponse,
|
IDataProviderHistoricalResponse,
|
||||||
IDataProviderResponse,
|
IDataProviderResponse,
|
||||||
MarketState
|
MarketState
|
||||||
@ -55,8 +56,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
|
|||||||
marketPrice,
|
marketPrice,
|
||||||
currency: scraperConfig?.currency,
|
currency: scraperConfig?.currency,
|
||||||
dataSource: DataSource.GHOSTFOLIO,
|
dataSource: DataSource.GHOSTFOLIO,
|
||||||
marketState: MarketState.delayed,
|
marketState: MarketState.delayed
|
||||||
name: scraperConfig?.name
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -66,6 +66,25 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getCustomSymbolsToGather(
|
||||||
|
startDate?: Date
|
||||||
|
): Promise<IDataGatheringItem[]> {
|
||||||
|
const ghostfolioSymbolProfiles =
|
||||||
|
await this.prismaService.symbolProfile.findMany({
|
||||||
|
where: {
|
||||||
|
dataSource: DataSource.GHOSTFOLIO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return ghostfolioSymbolProfiles.map(({ dataSource, symbol }) => {
|
||||||
|
return {
|
||||||
|
dataSource,
|
||||||
|
symbol,
|
||||||
|
date: startDate
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async getHistorical(
|
public async getHistorical(
|
||||||
aSymbols: string[],
|
aSymbols: string[],
|
||||||
aGranularity: Granularity = 'day',
|
aGranularity: Granularity = 'day',
|
||||||
|
@ -2,7 +2,6 @@ import { Currency } from '@prisma/client';
|
|||||||
|
|
||||||
export interface ScraperConfig {
|
export interface ScraperConfig {
|
||||||
currency: Currency;
|
currency: Currency;
|
||||||
name: string;
|
|
||||||
selector: string;
|
selector: string;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
url: string;
|
url: string;
|
||||||
|
@ -42,7 +42,7 @@ export interface IDataProviderResponse {
|
|||||||
marketChangePercent?: number;
|
marketChangePercent?: number;
|
||||||
marketPrice: number;
|
marketPrice: number;
|
||||||
marketState: MarketState;
|
marketState: MarketState;
|
||||||
name: string;
|
name?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user