mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
hotfix/fix-intrinio-load: (#5188)
* fix intrinio stocks load * update test_stocks_helper * makes --monthly --weekly work * pytest * fix test --------- Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
@@ -380,7 +380,9 @@ def load( # pylint: disable=too-many-return-statements
|
||||
)
|
||||
|
||||
elif source == "Intrinio":
|
||||
df_stock_candidate = load_stock_intrinio(symbol, start_date, end_date)
|
||||
df_stock_candidate = load_stock_intrinio(
|
||||
symbol, start_date, end_date, weekly, monthly
|
||||
)
|
||||
|
||||
elif source == "DataBento":
|
||||
df_stock_candidate = databento_model.get_historical_stock(
|
||||
|
||||
@@ -22,18 +22,37 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def load_stock_intrinio(
|
||||
symbol: str, start_date: datetime, end_date: datetime
|
||||
symbol: str,
|
||||
start_date: datetime,
|
||||
end_date: datetime,
|
||||
weekly: bool = False,
|
||||
monthly: bool = False,
|
||||
) -> pd.DataFrame:
|
||||
intrinio.ApiClient().set_api_key(get_current_user().credentials.API_INTRINIO_KEY)
|
||||
api = intrinio.SecurityApi()
|
||||
frequency: str = "daily"
|
||||
if weekly is True:
|
||||
frequency = "weekly"
|
||||
if monthly is True:
|
||||
frequency = "monthly"
|
||||
stock = api.get_security_stock_prices(
|
||||
symbol.upper(),
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
frequency="daily",
|
||||
frequency=frequency,
|
||||
page_size=10000,
|
||||
)
|
||||
df = pd.DataFrame(stock.to_dict()["stock_prices"])[
|
||||
data = stock
|
||||
while stock.next_page:
|
||||
stock = api.get_security_stock_prices(
|
||||
symbol.upper(),
|
||||
next_page=stock.next_page,
|
||||
page_size=10000,
|
||||
)
|
||||
data.stock_prices.extend(stock.stock_prices)
|
||||
data = data.to_dict()
|
||||
data = pd.DataFrame(data["stock_prices"])
|
||||
df = pd.DataFrame(data)[
|
||||
[
|
||||
"adj_open",
|
||||
"adj_high",
|
||||
@@ -43,9 +62,15 @@ def load_stock_intrinio(
|
||||
"date",
|
||||
"adj_volume",
|
||||
"dividend",
|
||||
"split_ratio",
|
||||
"change",
|
||||
"percent_change",
|
||||
"fifty_two_week_high",
|
||||
"fifty_two_week_low",
|
||||
]
|
||||
]
|
||||
df["date"] = pd.DatetimeIndex(df["date"])
|
||||
df["close"] = df["adj_close"]
|
||||
df = df.set_index("date").rename(
|
||||
columns={
|
||||
"adj_close": "Adj Close",
|
||||
@@ -54,6 +79,12 @@ def load_stock_intrinio(
|
||||
"adj_high": "High",
|
||||
"adj_low": "Low",
|
||||
"adj_volume": "Volume",
|
||||
"dividend": "Dividend",
|
||||
"split_ratio": "Split Ratio",
|
||||
"change": "Change",
|
||||
"percent_change": "Percent Change",
|
||||
"fifty_two_week_high": "52 Week High",
|
||||
"fifty_two_week_low": "52 Week Low",
|
||||
}
|
||||
)[::-1]
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
date,Open,High,Low,Close,Adj Close,Volume,dividend
|
||||
2021-12-01,49.85,50.02625,44.2525,179.84,44.96,2355535.0,0.0
|
||||
2021-12-02,46.25,46.8575,43.2675,181.56,45.39,2087100.0,0.0
|
||||
date,Open,High,Low,Close,Adj Close,Volume,Dividend,Split Ratio,Change,Percent Change,52 Week High,52 Week Low
|
||||
2021-12-01,49.85,50.02625,44.2525,44.96,44.96,2355535.0,0.0,1.0,-4.09,-0.0834,120.75,3.04
|
||||
2021-12-02,46.25,46.8575,43.2675,45.39,45.39,2087100.0,0.0,1.0,0.43,0.0096,120.75,3.04
|
||||
|
||||
|
@@ -1 +1 @@
|
||||
["Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread", "Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread", "Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread"]
|
||||
["Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread", "Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread", "Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread", "Long Straddle", "Long Strangle", "Long Strangle", "Long Strangle", "Bull Call Spread", "Bear Put Spread"]
|
||||
Reference in New Issue
Block a user