Skip to content

Commit

Permalink
feat(ticker): fetch pre/post market data with prepost arg of history
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Jun 22, 2024
1 parent e338b3a commit 7503eca
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
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
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

0 comments on commit 7503eca

Please sign in to comment.