Feature/add support for importing dividends from eod (#2910)
* Add support for importing dividends * Update changelog
This commit is contained in:
parent
a5ed49fe4c
commit
09ce8b1cd0
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Added
|
||||
|
||||
- Extended the date range support by week to date (`WTD`) and month to date (`MTD`) in the assistant (experimental)
|
||||
- Added support for importing dividends from _EOD Historical Data_
|
||||
- Added `healthcheck` for the _Ghostfolio_ service to the `docker-compose` files (`docker-compose.yml` and `docker-compose.build.yml`)
|
||||
|
||||
### Changed
|
||||
|
@ -134,7 +134,8 @@ export class DataProviderService {
|
||||
from,
|
||||
granularity,
|
||||
symbol,
|
||||
to
|
||||
to,
|
||||
requestTimeout: ms('30 seconds')
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
DataSource,
|
||||
SymbolProfile
|
||||
} from '@prisma/client';
|
||||
import { format, isToday } from 'date-fns';
|
||||
import { addDays, format, isSameDay, isToday } from 'date-fns';
|
||||
import got from 'got';
|
||||
|
||||
@Injectable()
|
||||
@ -54,9 +54,63 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
||||
};
|
||||
}
|
||||
|
||||
public async getDividends({}: GetDividendsParams) {
|
||||
public async getDividends({
|
||||
from,
|
||||
requestTimeout = this.configurationService.get('REQUEST_TIMEOUT'),
|
||||
symbol,
|
||||
to
|
||||
}: GetDividendsParams): Promise<{
|
||||
[date: string]: IDataProviderHistoricalResponse;
|
||||
}> {
|
||||
symbol = this.convertToEodSymbol(symbol);
|
||||
|
||||
if (isSameDay(from, to)) {
|
||||
to = addDays(to, 1);
|
||||
}
|
||||
|
||||
try {
|
||||
const abortController = new AbortController();
|
||||
|
||||
const response: {
|
||||
[date: string]: IDataProviderHistoricalResponse;
|
||||
} = {};
|
||||
|
||||
setTimeout(() => {
|
||||
abortController.abort();
|
||||
}, requestTimeout);
|
||||
|
||||
const historicalResult = await got(
|
||||
`${this.URL}/div/${symbol}?api_token=${
|
||||
this.apiKey
|
||||
}&fmt=json&from=${format(from, DATE_FORMAT)}&to=${format(
|
||||
to,
|
||||
DATE_FORMAT
|
||||
)}`,
|
||||
{
|
||||
// @ts-ignore
|
||||
signal: abortController.signal
|
||||
}
|
||||
).json<any>();
|
||||
|
||||
for (const { date, value } of historicalResult) {
|
||||
response[date] = {
|
||||
marketPrice: value
|
||||
};
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
Logger.error(
|
||||
`Could not get dividends for ${symbol} (${this.getName()}) from ${format(
|
||||
from,
|
||||
DATE_FORMAT
|
||||
)} to ${format(to, DATE_FORMAT)}: [${error.name}] ${error.message}`,
|
||||
'EodHistoricalDataService'
|
||||
);
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
public async getHistorical({
|
||||
from,
|
||||
|
@ -45,6 +45,7 @@ export interface DataProviderInterface {
|
||||
export interface GetDividendsParams {
|
||||
from: Date;
|
||||
granularity?: Granularity;
|
||||
requestTimeout?: number;
|
||||
symbol: string;
|
||||
to: Date;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user