You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
1013 B

import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { Injectable } from '@nestjs/common';
import { Currency } from '@prisma/client';
import { MarketDataService } from './market-data.service';
@Injectable()
export class CurrentRateService {
public constructor(
private readonly exchangeRateDataService: ExchangeRateDataService,
private readonly marketDataService: MarketDataService
) {}
public async getValue({
currency,
date,
symbol,
userCurrency
}: GetValueParams): Promise<number> {
const marketData = await this.marketDataService.get({
date,
symbol
});
if (marketData) {
return this.exchangeRateDataService.toCurrency(
marketData.marketPrice,
currency,
userCurrency
);
}
throw new Error(`Value not found for ${symbol} at ${date}`);
}
}
export interface GetValueParams {
date: Date;
symbol: string;
currency: Currency;
userCurrency: Currency;
}