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: { dataGatheringItem: {
dataSource: ghostfolioFearAndGreedIndexDataSourceCryptocurrencies, dataSource: ghostfolioFearAndGreedIndexDataSourceCryptocurrencies,
symbol: ghostfolioFearAndGreedIndexSymbolCryptocurrencies symbol: ghostfolioFearAndGreedIndexSymbolCryptocurrencies
} },
useIntradayData: true
}), }),
this.symbolService.get({ this.symbolService.get({
includeHistoricalData, includeHistoricalData,
dataGatheringItem: { dataGatheringItem: {
dataSource: ghostfolioFearAndGreedIndexDataSourceStocks, dataSource: ghostfolioFearAndGreedIndexDataSourceStocks,
symbol: ghostfolioFearAndGreedIndexSymbolStocks symbol: ghostfolioFearAndGreedIndexSymbolStocks
} },
useIntradayData: true
}) })
]); ]);

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

@ -24,15 +24,30 @@ export class SymbolService {
public async get({ public async get({
dataGatheringItem, dataGatheringItem,
includeHistoricalData includeHistoricalData,
useIntradayData = false
}: { }: {
dataGatheringItem: DataGatheringItem; dataGatheringItem: DataGatheringItem;
includeHistoricalData?: number; includeHistoricalData?: number;
useIntradayData?: boolean;
}): Promise<SymbolItem> { }): Promise<SymbolItem> {
const quotes = await this.dataProviderService.getQuotes({ let currency: string;
items: [dataGatheringItem] let marketPrice: number;
});
const { currency, marketPrice } = quotes[dataGatheringItem.symbol] ?? {}; 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) { if (dataGatheringItem.dataSource && marketPrice >= 0) {
let historicalData: HistoricalDataItem[] = []; 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) { public async getMax({ dataSource, symbol }: AssetProfileIdentifier) {
return this.prismaService.marketData.findFirst({ return this.prismaService.marketData.findFirst({
select: { select: {

Loading…
Cancel
Save