Skip to content

Commit

Permalink
Add include_today option to HistoricalReader
Browse files Browse the repository at this point in the history
  • Loading branch information
lsapan committed Apr 5, 2022
1 parent 64ee3af commit 909e70b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/source/whatsnew/v0.5.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Enhancements
- Re-added dropped ``date`` column in some calls (:issue:`238`)
- Added support for `Crytpocurrency Book <https://iexcloud.io/docs/api/#cryptocurrency-book>`__ - ``iexfinance.crypto.get_crypto_book``
- Added support for `Cryptocurrency Price <https://iexcloud.io/docs/api/#cryptocurrency-price>`__ - ``iexfinance.crypto.get_crypto_price``
- Added `include_today` option for `HistoricalReader` and `get_historical_data`

Bug Fixes
~~~~~~~~~
Expand Down
13 changes: 11 additions & 2 deletions iexfinance/stocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from iexfinance.utils.exceptions import ImmediateDeprecationError


def get_historical_data(symbols, start=None, end=None, close_only=False, **kwargs):
def get_historical_data(
symbols, start=None, end=None, close_only=False, include_today=False, **kwargs
):
"""
Function to obtain historical date for a symbol or list of
symbols. Return an instance of HistoricalReader
Expand All @@ -30,6 +32,8 @@ def get_historical_data(symbols, start=None, end=None, close_only=False, **kwarg
close_only: bool, default False
Returns adjusted data only with keys ``date``, ``close``, and
``volume``
include_today: bool, default False
Appends data from the current trading day
kwargs:
Additional Request Parameters (see base class)
Expand All @@ -39,7 +43,12 @@ def get_historical_data(symbols, start=None, end=None, close_only=False, **kwarg
Historical stock prices over date range, start to end
"""
return HistoricalReader(
symbols, start=start, end=end, close_only=close_only, **kwargs
symbols,
start=start,
end=end,
close_only=close_only,
include_today=False,
**kwargs
).fetch()


Expand Down
12 changes: 11 additions & 1 deletion iexfinance/stocks/historical.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ class HistoricalReader(Stock):
Reference: https://iextrading.com/developer/docs/#chart
"""

def __init__(self, symbols, start=None, end=None, close_only=False, **kwargs):
def __init__(
self,
symbols,
start=None,
end=None,
close_only=False,
include_today=False,
**kwargs
):
start = start or datetime.datetime.today() - datetime.timedelta(days=365)
self.start, self.end = _sanitize_dates(start, end)
self.close_only = close_only
self.include_today = include_today
super(HistoricalReader, self).__init__(symbols, **kwargs)

@property
Expand Down Expand Up @@ -58,6 +67,7 @@ def params(self):
"range": self.chart_range,
"chartByDay": self.single_day,
"chartCloseOnly": self.close_only,
"includeToday": self.include_today,
}
if self.single_day:
try:
Expand Down

0 comments on commit 909e70b

Please sign in to comment.