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
|
### Added
|
||||||
|
|
||||||
- Extended the date range support by week to date (`WTD`) and month to date (`MTD`) in the assistant (experimental)
|
- 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`)
|
- Added `healthcheck` for the _Ghostfolio_ service to the `docker-compose` files (`docker-compose.yml` and `docker-compose.build.yml`)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
@ -134,7 +134,8 @@ export class DataProviderService {
|
|||||||
from,
|
from,
|
||||||
granularity,
|
granularity,
|
||||||
symbol,
|
symbol,
|
||||||
to
|
to,
|
||||||
|
requestTimeout: ms('30 seconds')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
DataSource,
|
DataSource,
|
||||||
SymbolProfile
|
SymbolProfile
|
||||||
} from '@prisma/client';
|
} from '@prisma/client';
|
||||||
import { format, isToday } from 'date-fns';
|
import { addDays, format, isSameDay, isToday } from 'date-fns';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -54,8 +54,62 @@ export class EodHistoricalDataService implements DataProviderInterface {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getDividends({}: GetDividendsParams) {
|
public async getDividends({
|
||||||
return {};
|
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({
|
public async getHistorical({
|
||||||
|
@ -45,6 +45,7 @@ export interface DataProviderInterface {
|
|||||||
export interface GetDividendsParams {
|
export interface GetDividendsParams {
|
||||||
from: Date;
|
from: Date;
|
||||||
granularity?: Granularity;
|
granularity?: Granularity;
|
||||||
|
requestTimeout?: number;
|
||||||
symbol: string;
|
symbol: string;
|
||||||
to: Date;
|
to: Date;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user