Browse Source

Add data gathering mode to symbol profile and gather hourly

pull/7083/head
Thomas Kaul 4 weeks ago
parent
commit
6c4d968dd9
  1. 6
      apps/api/src/app/endpoints/market-data/market-data.controller.ts
  2. 25
      apps/api/src/app/symbol/symbol.service.ts
  3. 13
      apps/api/src/services/market-data/market-data.service.ts

6
apps/api/src/app/endpoints/market-data/market-data.controller.ts

@ -64,14 +64,16 @@ export class MarketDataController {
dataGatheringItem: {
dataSource: ghostfolioFearAndGreedIndexDataSourceCryptocurrencies,
symbol: ghostfolioFearAndGreedIndexSymbolCryptocurrencies
}
},
useIntradayData: true
}),
this.symbolService.get({
includeHistoricalData,
dataGatheringItem: {
dataSource: ghostfolioFearAndGreedIndexDataSourceStocks,
symbol: ghostfolioFearAndGreedIndexSymbolStocks
}
},
useIntradayData: true
})
]);

25
apps/api/src/app/symbol/symbol.service.ts

@ -24,15 +24,30 @@ export class SymbolService {
public async get({
dataGatheringItem,
includeHistoricalData
includeHistoricalData,
useIntradayData = false
}: {
dataGatheringItem: DataGatheringItem;
includeHistoricalData?: number;
useIntradayData?: boolean;
}): Promise<SymbolItem> {
const quotes = await this.dataProviderService.getQuotes({
items: [dataGatheringItem]
});
const { currency, marketPrice } = quotes[dataGatheringItem.symbol] ?? {};
let currency: string;
let marketPrice: number;
if (useIntradayData) {
const latestMarketData = await this.marketDataService.getLatest({
dataSource: dataGatheringItem.dataSource,
symbol: dataGatheringItem.symbol
});
marketPrice = latestMarketData?.marketPrice;
} else {
const quotes = await this.dataProviderService.getQuotes({
items: [dataGatheringItem]
});
({ currency, marketPrice } = quotes[dataGatheringItem.symbol] ?? {});
}
if (dataGatheringItem.dataSource && marketPrice >= 0) {
let historicalData: HistoricalDataItem[] = [];

13
apps/api/src/services/market-data/market-data.service.ts

@ -40,6 +40,19 @@ export class MarketDataService {
});
}
public async getLatest({
dataSource,
symbol
}: AssetProfileIdentifier): Promise<MarketData> {
return this.prismaService.marketData.findFirst({
orderBy: [{ date: 'desc' }],
where: {
dataSource,
symbol
}
});
}
public async getMax({ dataSource, symbol }: AssetProfileIdentifier) {
return this.prismaService.marketData.findFirst({
select: {

Loading…
Cancel
Save