mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-07 01:41:17 +00:00
* example changes in slopes * change lettering size and side bar capitalization * revert back to Fira * start automatic website generation * this was autogen * add examples to slopes model * generate slopes doc * change to _index.md * allow italic formatting * fix regex * option to regenerate paths * update alt docs * fix generate * update alt * fix generate * update common * target italic only for types * format alt * format italic common * add sig indentation * update sig indent alt * update common ident * add todo * generate docstrings for all menus * fix maxdd * fix returns font size * fix keys docs * fix more docstrings * escape literal symbols * escape literal symbols * reformat keys * format opt * remove literal escape * remove another literal escape * remove another literal escape * unindent returns * update docs return unindent * add comma in last arg * fix funcs without params * fix signature * compact some code * refactor some more code * refactor some code * some final cleanup * write docstrings * change main * move futures paths * generate futures docs * add external axes references * fix typo * revert to double docstring * fix small bug * remove docs folder * generate.py in website folder * add forecast to docs * clear some warnings * fix underscore * remove cite * refresh website docs * fix forecast docstrings * fix po * fix po docs and remove italic * fix more docstrings * remove last warning * codespell * flake8 * exclude website contente from flake * noqa on optimizer * update website * fix mypy * remove setup from mypy * mypy to openbbterminal * update precommit * pylint * try to remove sdk loading issue * fix dates active command * fix crypto.change formats * fix eb formats * nonzero fix * format dates crypto.load * format supply transac * format hr altindex * format load crypto * regenerate docs * format ba trend dates * regenerate docs * format ba trend * candle defaults * fix sentiment test * remove unused import * shopt * shopt again * revert crypto helpers * test shopt * fix some tests * skip trending test * fix alcoin test * helpers * write docs * rewrite helper * fix crypto dd defaults * fix some date defaults * regenerate website * fix santiment model * fix get trending * fix more defaults * generate website * fix ftd view data default * black * regenerate website docs * regenerate docs * refactor remaining funcs * pcr doc * Checkout from main * flake8 * regenerate docs * regenerate docs * fix build Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com> Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
"""Polygon.io model"""
|
|
__docformat__ = "numpy"
|
|
|
|
from datetime import datetime
|
|
import requests
|
|
import pandas as pd
|
|
from openbb_terminal.config_terminal import API_POLYGON_KEY as api_key
|
|
from openbb_terminal.helper_funcs import get_user_agent
|
|
from openbb_terminal.decorators import check_api_key
|
|
from openbb_terminal.rich_config import console
|
|
|
|
# pylint: disable=unsupported-assignment-operation
|
|
|
|
|
|
@check_api_key(["API_POLYGON_KEY"])
|
|
def get_historical(
|
|
fx_pair: str,
|
|
multiplier: int = 1,
|
|
timespan: str = "day",
|
|
start_date: str = "2000-01-01",
|
|
end_date: str = None,
|
|
) -> pd.DataFrame:
|
|
"""Load historical fx data from polygon
|
|
|
|
Parameters
|
|
----------
|
|
fx_pair: str
|
|
Forex pair to download
|
|
multiplier: int
|
|
Multiplier for timespan. 5 with minute timespan indicated 5min windows
|
|
timespan: str
|
|
Window to aggregate data.
|
|
start_date : str
|
|
Initial date, format YYYY-MM-DD
|
|
end_date : str
|
|
Final date, format YYYY-MM-DD
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
Dataframe of historical forex prices
|
|
"""
|
|
|
|
if end_date is None:
|
|
end_date = datetime.now().date().strftime("%Y-%m-%d")
|
|
|
|
request_url = (
|
|
f"https://api.polygon.io/v2/aggs/ticker/C:{fx_pair}/range"
|
|
f"/{multiplier}/{timespan}/{start_date}/{end_date}?adjusted=true&sort=desc&limit=50000&apiKey={api_key}"
|
|
)
|
|
json_response = requests.get(
|
|
request_url, headers={"User-Agent": get_user_agent()}
|
|
).json()
|
|
|
|
if json_response["status"] == "ERROR":
|
|
console.print(f"[red]{json_response['error']}[/red]\n")
|
|
return pd.DataFrame()
|
|
|
|
if "results" not in json_response.keys():
|
|
console.print("[red]Error in polygon request[/red]\n")
|
|
return pd.DataFrame()
|
|
|
|
historical = pd.DataFrame(json_response["results"]).rename(
|
|
columns={
|
|
"o": "Open",
|
|
"c": "Close",
|
|
"h": "High",
|
|
"l": "Low",
|
|
"t": "date",
|
|
"v": "Volume",
|
|
"n": "Transactions",
|
|
}
|
|
)
|
|
historical["date"] = pd.to_datetime(historical.date, unit="ms")
|
|
historical = historical.sort_values(by="date", ascending=True)
|
|
historical = historical.set_index("date")
|
|
return historical
|