|
|
@ -20,6 +20,11 @@ import { Injectable, Logger } from '@nestjs/common';
|
|
|
|
import { DataSource, SymbolProfile } from '@prisma/client';
|
|
|
|
import { DataSource, SymbolProfile } from '@prisma/client';
|
|
|
|
import { addDays, format, isSameDay } from 'date-fns';
|
|
|
|
import { addDays, format, isSameDay } from 'date-fns';
|
|
|
|
import yahooFinance from 'yahoo-finance2';
|
|
|
|
import yahooFinance from 'yahoo-finance2';
|
|
|
|
|
|
|
|
import { ChartResultArray } from 'yahoo-finance2/dist/esm/src/modules/chart';
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
|
|
|
HistoricalDividendsResult,
|
|
|
|
|
|
|
|
HistoricalHistoryResult
|
|
|
|
|
|
|
|
} from 'yahoo-finance2/dist/esm/src/modules/historical';
|
|
|
|
import { Quote } from 'yahoo-finance2/dist/esm/src/modules/quote';
|
|
|
|
import { Quote } from 'yahoo-finance2/dist/esm/src/modules/quote';
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
@Injectable()
|
|
|
@ -60,7 +65,8 @@ export class YahooFinanceService implements DataProviderInterface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const historicalResult = await yahooFinance.historical(
|
|
|
|
const historicalResult = this.convertToDividendResult(
|
|
|
|
|
|
|
|
await yahooFinance.chart(
|
|
|
|
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
|
|
|
|
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
|
|
|
|
symbol
|
|
|
|
symbol
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -70,8 +76,8 @@ export class YahooFinanceService implements DataProviderInterface {
|
|
|
|
period1: format(from, DATE_FORMAT),
|
|
|
|
period1: format(from, DATE_FORMAT),
|
|
|
|
period2: format(to, DATE_FORMAT)
|
|
|
|
period2: format(to, DATE_FORMAT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const response: {
|
|
|
|
const response: {
|
|
|
|
[date: string]: IDataProviderHistoricalResponse;
|
|
|
|
[date: string]: IDataProviderHistoricalResponse;
|
|
|
|
} = {};
|
|
|
|
} = {};
|
|
|
@ -108,7 +114,8 @@ export class YahooFinanceService implements DataProviderInterface {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const historicalResult = await yahooFinance.historical(
|
|
|
|
const historicalResult = this.convertToHistoricalResult(
|
|
|
|
|
|
|
|
await yahooFinance.chart(
|
|
|
|
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
|
|
|
|
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(
|
|
|
|
symbol
|
|
|
|
symbol
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -117,6 +124,7 @@ export class YahooFinanceService implements DataProviderInterface {
|
|
|
|
period1: format(from, DATE_FORMAT),
|
|
|
|
period1: format(from, DATE_FORMAT),
|
|
|
|
period2: format(to, DATE_FORMAT)
|
|
|
|
period2: format(to, DATE_FORMAT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const response: {
|
|
|
|
const response: {
|
|
|
@ -302,6 +310,20 @@ export class YahooFinanceService implements DataProviderInterface {
|
|
|
|
return { items };
|
|
|
|
return { items };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private convertToDividendResult(
|
|
|
|
|
|
|
|
result: ChartResultArray
|
|
|
|
|
|
|
|
): HistoricalDividendsResult {
|
|
|
|
|
|
|
|
return result.events.dividends.map(({ amount: dividends, date }) => {
|
|
|
|
|
|
|
|
return { date, dividends };
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private convertToHistoricalResult(
|
|
|
|
|
|
|
|
result: ChartResultArray
|
|
|
|
|
|
|
|
): HistoricalHistoryResult {
|
|
|
|
|
|
|
|
return result.quotes;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private async getQuotesWithQuoteSummary(aYahooFinanceSymbols: string[]) {
|
|
|
|
private async getQuotesWithQuoteSummary(aYahooFinanceSymbols: string[]) {
|
|
|
|
const quoteSummaryPromises = aYahooFinanceSymbols.map((symbol) => {
|
|
|
|
const quoteSummaryPromises = aYahooFinanceSymbols.map((symbol) => {
|
|
|
|
return yahooFinance.quoteSummary(symbol).catch(() => {
|
|
|
|
return yahooFinance.quoteSummary(symbol).catch(() => {
|
|
|
|