mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-12-01 05:33:37 +00:00
Fix futures curve
This commit is contained in:
@@ -475,14 +475,13 @@ async def download_plotly_js():
|
||||
# this is so we don't have to block the main thread
|
||||
async with aiohttp.ClientSession(
|
||||
connector=aiohttp.TCPConnector(verify_ssl=False)
|
||||
) as session:
|
||||
async with session.get(f"https://cdn.plot.ly/{js_filename}") as resp:
|
||||
with open(str(PLOTLYJS_PATH), "wb") as f:
|
||||
while True:
|
||||
chunk = await resp.content.read(1024)
|
||||
if not chunk:
|
||||
break
|
||||
f.write(chunk)
|
||||
) as session, session.get(f"https://cdn.plot.ly/{js_filename}") as resp:
|
||||
with open(str(PLOTLYJS_PATH), "wb") as f:
|
||||
while True:
|
||||
chunk = await resp.content.read(1024)
|
||||
if not chunk:
|
||||
break
|
||||
f.write(chunk)
|
||||
|
||||
# We delete the old version of plotly.js
|
||||
for file in (PLOTS_CORE_PATH / "assets").glob("plotly*.js"):
|
||||
|
||||
@@ -42,7 +42,7 @@ class CLASS_crypto(Container):
|
||||
provider: Optional[Literal["fmp", "polygon", "yfinance"]] = None,
|
||||
**kwargs
|
||||
) -> OBBject[List]:
|
||||
"""Crypto EOD Price.
|
||||
r"""Crypto EOD Price.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -118,11 +118,11 @@ class CLASS_crypto(Container):
|
||||
change : Optional[float]
|
||||
Change in the price of the symbol from the previous day. (provider: fmp)
|
||||
change_percent : Optional[float]
|
||||
Change \\% in the price of the symbol. (provider: fmp)
|
||||
Change \% in the price of the symbol. (provider: fmp)
|
||||
label : Optional[str]
|
||||
Human readable format of the date. (provider: fmp)
|
||||
change_over_time : Optional[float]
|
||||
Change \\% in the price of the symbol over a period of time. (provider: fmp)
|
||||
Change \% in the price of the symbol over a period of time. (provider: fmp)
|
||||
n : Optional[PositiveInt]
|
||||
Number of transactions for the symbol in the time period. (provider: polygon)
|
||||
""" # noqa: E501
|
||||
|
||||
@@ -674,7 +674,7 @@ class CLASS_economy(Container):
|
||||
provider: Optional[Literal["fmp", "polygon", "yfinance"]] = None,
|
||||
**kwargs
|
||||
) -> OBBject[List]:
|
||||
"""Get OHLCV data for an index.
|
||||
r"""Get OHLCV data for an index.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -750,11 +750,11 @@ class CLASS_economy(Container):
|
||||
change : Optional[float]
|
||||
Change in the price of the symbol from the previous day. (provider: fmp)
|
||||
change_percent : Optional[float]
|
||||
Change \\% in the price of the symbol. (provider: fmp)
|
||||
Change \% in the price of the symbol. (provider: fmp)
|
||||
label : Optional[str]
|
||||
Human readable format of the date. (provider: fmp)
|
||||
change_over_time : Optional[float]
|
||||
Change \\% in the price of the symbol over a period of time. (provider: fmp)
|
||||
Change \% in the price of the symbol over a period of time. (provider: fmp)
|
||||
n : Optional[PositiveInt]
|
||||
Number of transactions for the symbol in the time period. (provider: polygon)
|
||||
""" # noqa: E501
|
||||
|
||||
@@ -43,7 +43,7 @@ class CLASS_forex(Container):
|
||||
provider: Optional[Literal["fmp", "polygon", "yfinance"]] = None,
|
||||
**kwargs
|
||||
) -> OBBject[List]:
|
||||
"""Forex Intraday Price.
|
||||
r"""Forex Intraday Price.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -117,11 +117,11 @@ class CLASS_forex(Container):
|
||||
change : Optional[float]
|
||||
Change in the price of the symbol from the previous day. (provider: fmp)
|
||||
change_percent : Optional[float]
|
||||
Change \\% in the price of the symbol. (provider: fmp)
|
||||
Change \% in the price of the symbol. (provider: fmp)
|
||||
label : Optional[str]
|
||||
Human readable format of the date. (provider: fmp)
|
||||
change_over_time : Optional[float]
|
||||
Change \\% in the price of the symbol over a period of time. (provider: fmp)
|
||||
Change \% in the price of the symbol over a period of time. (provider: fmp)
|
||||
n : Optional[PositiveInt]
|
||||
Number of transactions for the symbol in the time period. (provider: polygon)
|
||||
""" # noqa: E501
|
||||
|
||||
@@ -218,7 +218,7 @@ class CLASS_stocks(Container):
|
||||
provider: Optional[Literal["cboe", "fmp", "polygon", "yfinance"]] = None,
|
||||
**kwargs
|
||||
) -> OBBject[List]:
|
||||
"""Load stock data for a specific ticker.
|
||||
r"""Load stock data for a specific ticker.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -294,11 +294,11 @@ class CLASS_stocks(Container):
|
||||
change : Optional[float]
|
||||
Change in the price of the symbol from the previous day. (provider: fmp)
|
||||
change_percent : Optional[float]
|
||||
Change \\% in the price of the symbol. (provider: fmp)
|
||||
Change \% in the price of the symbol. (provider: fmp)
|
||||
label : Optional[str]
|
||||
Human readable format of the date. (provider: fmp)
|
||||
change_over_time : Optional[float]
|
||||
Change \\% in the price of the symbol over a period of time. (provider: fmp)
|
||||
Change \% in the price of the symbol over a period of time. (provider: fmp)
|
||||
n : Optional[PositiveInt]
|
||||
Number of transactions for the symbol in the time period. (provider: polygon)
|
||||
""" # noqa: E501
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""yfinance Futures End of Day fetcher."""
|
||||
|
||||
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
@@ -45,13 +44,23 @@ class YFinanceFuturesCurveFetcher(
|
||||
query: YFinanceFuturesCurveQueryParams,
|
||||
credentials: Optional[Dict[str, str]],
|
||||
**kwargs: Any,
|
||||
) -> dict:
|
||||
) -> List[dict]:
|
||||
"""Return the raw data from the yfinance endpoint."""
|
||||
return get_futures_curve(query.symbol, query.date).to_dict(orient="records")
|
||||
data = get_futures_curve(query.symbol, query.date).to_dict(orient="records")
|
||||
if len(data) == 0:
|
||||
warnings.warn(f"Symbol {query.symbol} not found in yfinance")
|
||||
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def transform_data(
|
||||
data: dict,
|
||||
) -> List[YFinanceFuturesCurveData]:
|
||||
"""Transform the data to the standard format."""
|
||||
return [YFinanceFuturesCurveData.parse_obj(d) for d in data]
|
||||
return [
|
||||
YFinanceFuturesCurveData(
|
||||
expiration=curve["expiration"],
|
||||
price=curve["Last Price"],
|
||||
)
|
||||
for curve in data
|
||||
]
|
||||
|
||||
@@ -16,7 +16,7 @@ from openbb_yfinance.utils.references import MONTHS
|
||||
|
||||
|
||||
def get_futures_data() -> pd.DataFrame:
|
||||
"""Return the dataframe of the futures csv file"""
|
||||
"""Return the dataframe of the futures csv file."""
|
||||
return pd.read_csv(Path(__file__).resolve().parent / "futures.csv")
|
||||
|
||||
|
||||
@@ -36,7 +36,11 @@ def get_futures_curve(symbol: str, date: Optional[dateType]) -> pd.DataFrame:
|
||||
DataFrame with futures curve
|
||||
"""
|
||||
futures_data = get_futures_data()
|
||||
exchange = futures_data[futures_data["Ticker"] == symbol]["Exchange"].values[0]
|
||||
try:
|
||||
exchange = futures_data[futures_data["Ticker"] == symbol]["Exchange"].values[0]
|
||||
except IndexError:
|
||||
return pd.DataFrame({"Last Price": [], "expiration": []})
|
||||
|
||||
today = datetime.today()
|
||||
futures_index = []
|
||||
futures_curve = []
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import pytest
|
||||
from openbb_core.app.charting_manager import ChartingManager
|
||||
from openbb_core.app.model.system_settings import SystemSettings
|
||||
from openbb_core.app.model.user_settings import UserSettings
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
@pytest.fixture(scope="function", autouse=True)
|
||||
def setup_and_teardown():
|
||||
|
||||
Reference in New Issue
Block a user