Feature/extend get historical in financial modeling prep service (#4229)
* Extend get historical * Update changelog
This commit is contained in:
parent
04d7792b8b
commit
39ac6f352f
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- Extended the _Financial Modeling Prep_ service
|
||||||
- Improved the language localization for Ukrainian (`uk`)
|
- Improved the language localization for Ukrainian (`uk`)
|
||||||
- Upgraded `date-fns` from version `3.6.0` to `4.1.0`
|
- Upgraded `date-fns` from version `3.6.0` to `4.1.0`
|
||||||
- Upgraded `rxjs` from version `7.5.6` to `7.8.1`
|
- Upgraded `rxjs` from version `7.5.6` to `7.8.1`
|
||||||
|
@ -29,6 +29,7 @@ import { isISIN } from 'class-validator';
|
|||||||
import { countries } from 'countries-list';
|
import { countries } from 'countries-list';
|
||||||
import {
|
import {
|
||||||
addDays,
|
addDays,
|
||||||
|
addYears,
|
||||||
format,
|
format,
|
||||||
isAfter,
|
isAfter,
|
||||||
isBefore,
|
isBefore,
|
||||||
@ -273,30 +274,44 @@ export class FinancialModelingPrepService implements DataProviderInterface {
|
|||||||
}: GetHistoricalParams): Promise<{
|
}: GetHistoricalParams): Promise<{
|
||||||
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
||||||
}> {
|
}> {
|
||||||
|
const MAX_YEARS_PER_REQUEST = 5;
|
||||||
|
const result: {
|
||||||
|
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
||||||
|
} = {
|
||||||
|
[symbol]: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
let currentFrom = from;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { historical } = await fetch(
|
while (isBefore(currentFrom, to) || isSameDay(currentFrom, to)) {
|
||||||
`${this.URL}/historical-price-full/${symbol}?apikey=${this.apiKey}`,
|
const currentTo = isBefore(
|
||||||
{
|
addYears(currentFrom, MAX_YEARS_PER_REQUEST),
|
||||||
signal: AbortSignal.timeout(requestTimeout)
|
to
|
||||||
}
|
)
|
||||||
).then((res) => res.json());
|
? addYears(currentFrom, MAX_YEARS_PER_REQUEST)
|
||||||
|
: to;
|
||||||
|
|
||||||
const result: {
|
const { historical } = await fetch(
|
||||||
[symbol: string]: { [date: string]: IDataProviderHistoricalResponse };
|
`${this.URL}/historical-price-full/${symbol}?apikey=${this.apiKey}&from=${format(currentFrom, DATE_FORMAT)}&to=${format(currentTo, DATE_FORMAT)}`,
|
||||||
} = {
|
{
|
||||||
[symbol]: {}
|
signal: AbortSignal.timeout(requestTimeout)
|
||||||
};
|
}
|
||||||
|
).then((res) => res.json());
|
||||||
|
|
||||||
for (const { adjClose, date } of historical) {
|
for (const { adjClose, date } of historical) {
|
||||||
if (
|
if (
|
||||||
(isSameDay(parseDate(date), from) ||
|
(isSameDay(parseDate(date), currentFrom) ||
|
||||||
isAfter(parseDate(date), from)) &&
|
isAfter(parseDate(date), currentFrom)) &&
|
||||||
isBefore(parseDate(date), to)
|
isBefore(parseDate(date), currentTo)
|
||||||
) {
|
) {
|
||||||
result[symbol][date] = {
|
result[symbol][date] = {
|
||||||
marketPrice: adjClose
|
marketPrice: adjClose
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentFrom = addYears(currentFrom, MAX_YEARS_PER_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user