Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add prepost arg to Ticker.history to fetch Pre/Post market data #281

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/guide/ticker/historical.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
| end | Specific ending date | `str` or `datetime.datetime` | | optional | If a string is passed, use the format `YYYY-MM-DD`
| adj_timezone | Adjust datetime to the specific symbol's timezone | `bool` | `True` | optional | `True`<br>`False`
| adj_ohlc | Calculates an adjusted open, high, low and close prices according to split and dividend information | `bool` | `False` | optional | `True`<br>`False`
| prepost | Include Pre and Post market data | `bool` | `False` | optional | `True`<br>`False`

!!! tip "One Minute Interval Data"
The Yahoo Finance API restricts the amount of one minute interval data to seven days per request. However, the data availability extends to 30 days. The following will allow the user to retrieve the last 30 days of one minute interval data, with the one caveat that **4 requests are made in 7 day ranges to retrieve the desired data**:
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ def test_p_get_financial_data(ticker):


@pytest.mark.parametrize(
"period, interval",
"period, interval, prepost",
[
(p, i)
for p, i in zip(
["1d", "1mo", "1y", "5y", "max"], ["1m", "1m", "1d", "1wk", "3mo"]
(p, i, prepost)
for p, i, prepost in zip(
["1d", "1mo", "1y", "5y", "max"],
["1m", "1m", "1d", "1wk", "3mo"],
[True, False, True, False, False],
)
],
)
def test_history(ticker, period, interval):
def test_history(ticker, period, interval, prepost):
assert isinstance(ticker.history(period, interval), pd.DataFrame)


Expand Down
1 change: 1 addition & 0 deletions yahooquery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ class _YahooFinance(object):
"events": {"required": False, "default": "div,split"},
"numberOfPoints": {"required": False, "default": None},
"formatted": {"required": False, "default": False},
"includePrePost": {"required": False, "default": None},
},
},
"options": {
Expand Down
4 changes: 4 additions & 0 deletions yahooquery/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ def history(
end=None,
adj_timezone=True,
adj_ohlc=False,
prepost=False,
):
"""
Historical pricing data
Expand All @@ -1256,6 +1257,8 @@ def history(
adj_ohlc: bool, default False, optional
Calculates an adjusted open, high, low and close prices according
to split and dividend information
prepost: bool, default False, optional
Include Pre and Post market data.

Returns
-------
Expand Down Expand Up @@ -1287,6 +1290,7 @@ def history(
"Interval values must be one of {}".format(", ".join(intervals))
)
params["interval"] = interval.lower()
params["includePrePost"] = prepost
if params["interval"] == "1m" and period == "1mo":
df = self._history_1m(adj_timezone, adj_ohlc)
else:
Expand Down
Loading