Skip to content

Commit af46ab2

Browse files
committed
Added parameters to technical indicator API
1 parent f33ffb4 commit af46ab2

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

eodhd/APIs/TechnicalIndicatorAPI.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ class TechnicalIndicatorAPI(BaseAPI):
1010

1111
def get_technical_indicator_data(self, api_token: str, ticker: str, function: str, period: int = 50,
1212
date_from: str = None, date_to: str = None, order: str = 'a',
13-
splitadjusted_only: str = '0'):
13+
splitadjusted_only: str = '0', agg_period = None,
14+
fast_kperiod = None, slow_kperiod = None, slow_dperiod = None,
15+
fast_dperiod = None, fast_period = None, slow_period = None,
16+
signal_period = None, acceleration = None, maximum = None):
1417
endpoint = 'technical/'
1518

1619
if ticker.strip() == "" or ticker is None:
@@ -29,6 +32,41 @@ def get_technical_indicator_data(self, api_token: str, ticker: str, function: st
2932
if date_from is not None:
3033
query_string += "&from=" + date_from
3134

35+
if function == 'splitadjusted':
36+
possible_agg_period = ['d', 'w', 'm']
37+
if agg_period is not None:
38+
if agg_period not in possible_agg_period:
39+
raise ValueError("agg_period must be in ['d', 'w', 'm']")
40+
query_string += "&agg_period=" + agg_period
41+
42+
if function == 'stochastic':
43+
if fast_kperiod is not None:
44+
query_string += "&fast_kperiod=" + fast_kperiod
45+
if slow_kperiod is not None:
46+
query_string += "&slow_kperiod=" + slow_kperiod
47+
if slow_dperiod is not None:
48+
query_string += "&slow_dperiod=" + slow_dperiod
49+
50+
if function == 'stochrsi':
51+
if fast_kperiod is not None:
52+
query_string += "&fast_kperiod=" + fast_kperiod
53+
if fast_dperiod is not None:
54+
query_string += "&fast_dperiod=" + fast_dperiod
55+
56+
if function == 'macd':
57+
if fast_period is not None:
58+
query_string += "&fast_period=" + fast_period
59+
if slow_period is not None:
60+
query_string += "&slow_period=" + slow_period
61+
if signal_period is not None:
62+
query_string += "&signal_period=" + signal_period
63+
64+
if function == 'sar':
65+
if acceleration is not None:
66+
query_string += "&acceleration=" + acceleration
67+
if maximum is not None:
68+
query_string += "&maximum=" + maximum
69+
3270
return self._rest_get_method(api_key = api_token, endpoint = endpoint, uri = ticker, querystring = query_string)
3371

3472

eodhd/apiclient.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,16 @@ def get_technical_indicator_data(
454454
date_to: str = None,
455455
order: str = "a",
456456
splitadjusted_only: str = "0",
457+
agg_period: str = None,
458+
fast_kperiod: int = None,
459+
slow_kperiod: int = None,
460+
slow_dperiod: int = None,
461+
fast_dperiod: int = None,
462+
fast_period: int = None,
463+
slow_period: int = None,
464+
signal_period: int = None,
465+
acceleration: float = None,
466+
maximum: float = None
457467
) -> list:
458468
"""Available args:
459469
ticker (required) - consists of two parts: [SYMBOL_NAME].[EXCHANGE_ID]. Example: AAPL.US
@@ -464,16 +474,35 @@ def get_technical_indicator_data(
464474
'cci', 'sar', 'bbands', 'format_amibroker', 'splitadjusted']
465475
Description for possible functions you get here:
466476
https://eodhistoricaldata.com/financial-apis/technical-indicators-api/
467-
period the number of data points used to calculate each moving average value.
468-
Valid range from 2 to 100000 with the default value 50.
477+
period - the number of data points used to calculate each moving average value.
478+
Valid range from 2 to 100000 with the default value - 50.
469479
date_from (not required) - date from with format Y-m-d. Example: 2000-01-01
470480
date_to (not required) - date from with format Y-m-d. Example: 2000-01-01
471-
order use ‘a’ for ascending dates (from old to new) and ‘d’ for descending dates (from new to old).
481+
order - use 'a' for ascending dates (from old to new) and 'd' for descending dates (from new to old).
472482
By default, dates are shown in ascending order.
473-
splitadjusted_only default value is ‘0’.
483+
splitadjusted_only - default value is '0'.
474484
By default, we calculate data for some functions by closes adjusted with splits and dividends.
475-
If you need to calculate the data by closes adjusted only with splits, set this parameter to ‘1’.
485+
If you need to calculate the data by closes adjusted only with splits, set this parameter to '1'.
476486
Works with the following functions: sma, ema, wma, volatility, rsi, slope, and macd.
487+
488+
For some functions can be used additional parameters:
489+
1. For splitadjusted:
490+
agg_period [optional] – aggregation period. Default value – 'd'. Possible values: d – daily, w – weekly, m – monthly.
491+
2. For stochastic:
492+
fast_kperiod [optional] – Fast K-period, the default value is 14. Valid range from 2 to 100000.
493+
slow_kperiod [optional] – Slow K-period, the default value is 3. Valid range from 2 to 100000.
494+
slow_dperiod [optional] – Slow D-period, the default value is 3. Valid range from 2 to 100000.
495+
3. For stochrsi:
496+
fast_kperiod [optional] – Fast K-period, the default value is 14. Valid range from 2 to 100000.
497+
fast_dperiod [optional] – Fast D-period, the default value is 14. Valid range from 2 to 100000.
498+
4. For macd:
499+
fast_period [optional] – the default value is 12. Valid range from 2 to 100000.
500+
slow_period [optional] – the default value is 26. Valid range from 2 to 100000.
501+
signal_period [optional] – the default value is 9. Valid range from 2 to 100000.
502+
5. For sar:
503+
acceleration [optional] – Acceleration Factor used up to the Maximum value. Default value – 0.02.
504+
maximum [optional] – Acceleration Factor Maximum value. Default value – 0.20.
505+
For those functions use this parameters to set periods.
477506
"""
478507

479508
api_call = TechnicalIndicatorAPI()
@@ -486,6 +515,16 @@ def get_technical_indicator_data(
486515
date_to=date_to,
487516
order=order,
488517
splitadjusted_only=splitadjusted_only,
518+
agg_period=agg_period,
519+
fast_kperiod=fast_kperiod,
520+
slow_kperiod=slow_kperiod,
521+
slow_dperiod=slow_dperiod,
522+
fast_dperiod=fast_dperiod,
523+
fast_period=fast_period,
524+
slow_period=slow_period,
525+
signal_period=signal_period,
526+
acceleration=acceleration,
527+
maximum=maximum
489528
)
490529

491530
def get_live_stock_prices(self, ticker, date_to=None, date_from=None, s=None) -> list:

0 commit comments

Comments
 (0)