Skip to content

Commit

Permalink
Merge branch 'develop' into feature/websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone authored Jan 16, 2025
2 parents 6f8c543 + 58b252c commit 4bf4821
Show file tree
Hide file tree
Showing 39 changed files with 7,058 additions and 1,857 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Placeholder for the OpenBB Platform Installer package."""

__version__ = "1.0.0"
__version__ = "1.0.2"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# If you will be using this as a template for your own package, please change the values accordingly.
[tool.poetry]
name = "openbb_platform_installer" # Change this to your package name
version = "1.0.0" # Change this to your package version
version = "1.0.2" # Change this to your package version
description = "A meta package for installing the OpenBB Platform: Investment research for everyone, anywhere." # Change this to your description
authors = ["OpenBB <[email protected]>"] # Change this to your name and email
license = "AGPL-3.0-only" # This license must be compatible with the OpenBB license
Expand Down
1 change: 0 additions & 1 deletion build/conda/installer/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ channels:

condarc:
{channels: [conda-forge],
default_channels: [conda-forge],
allow_softlinks: false,
auto_activate_base: false,
always_copy: true,
Expand Down
2 changes: 1 addition & 1 deletion build/conda/installer/post_install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python -m pip install -U pip >> "%LOG_FILE%" 2>&1

pip install -U setuptools >> "%LOG_FILE%" 2>&1

pip install poetry >> "%LOG_FILE%" 2>&1
pip install poetry==1.8.5 >> "%LOG_FILE%" 2>&1

poetry config virtualenvs.path "%PREFIX%\envs" --local >> "%LOG_FILE%" 2>&1

Expand Down
2 changes: 2 additions & 0 deletions build/conda/installer/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ python -m pip install -U pip >>"$LOG_FILE" 2>&1

pip install -U setuptools poetry >>"$LOG_FILE" 2>&1

pip install poetry==1.8.5 >>"$LOG_FILE" 2>&1

poetry config virtualenvs.path "$PREFIX/envs" --local >>"$LOG_FILE" 2>&1

poetry config virtualenvs.create false --local >>"$LOG_FILE" 2>&1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
"""Compare Groups Model."""

from typing import Optional

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from pydantic import Field


class CompareGroupsQueryParams(QueryParams):
"""Compare Groups Query."""

group: Optional[str] = Field(
default=None,
description="The group to compare - i.e., 'sector', 'industry', 'country'. Choices vary by provider.",
)
metric: Optional[str] = Field(
default=None,
description="The type of metrics to compare - i.e, 'valuation', 'performance'. Choices vary by provider.",
)


class CompareGroupsData(Data):
"""Compare Groups Data."""

name: str = Field(description="Name or label of the group.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Futures Info Standard Model."""

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.descriptions import DATA_DESCRIPTIONS
from pydantic import Field


class FuturesInfoQueryParams(QueryParams):
"""Futures Info Query."""

# leaving this empty to let the provider create custom symbol docstrings.


class FuturesInfoData(Data):
"""Futures Instruments Data."""

symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Futures Instruments Standard Model."""

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams


class FuturesInstrumentsQueryParams(QueryParams):
"""Futures Instruments Query."""


class FuturesInstrumentsData(Data):
"""Futures Instruments Data."""
4 changes: 2 additions & 2 deletions openbb_platform/dev_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def install_platform_local(_extras: bool = False):
extras_args = ["-E", "all"] if _extras else []

subprocess.run(
CMD + ["lock", "--no-update"],
CMD + ["lock"],
cwd=PLATFORM_PATH,
check=True,
)
Expand Down Expand Up @@ -193,7 +193,7 @@ def install_platform_cli():
CMD = [sys.executable, "-m", "poetry"]

subprocess.run(
CMD + ["lock", "--no-update"],
CMD + ["lock"],
cwd=CLI_PATH,
check=True, # noqa: S603
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ def test_derivatives_options_unusual(params, headers):
"expiration": "2025-12",
}
),
(
{
"provider": "deribit",
"interval": "1d",
"symbol": "BTC,ETH",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
],
)
@pytest.mark.integration
Expand Down Expand Up @@ -144,6 +153,7 @@ def test_derivatives_futures_historical(params, headers):
"date": "2024-06-25",
}
),
({"provider": "deribit", "date": None, "symbol": "BTC", "hours_ago": 12}),
],
)
@pytest.mark.integration
Expand All @@ -164,7 +174,9 @@ def test_derivatives_futures_curve(params, headers):
({"provider": "intrinio", "date": None, "only_traded": True}),
],
)
@pytest.mark.integration
@pytest.mark.skip(
reason="This test is skipped because the download is excessively large."
)
def test_derivatives_options_snapshots(params, headers):
"""Test the options snapshots endpoint."""
params = {p: v for p, v in params.items() if v}
Expand All @@ -174,3 +186,39 @@ def test_derivatives_options_snapshots(params, headers):
result = requests.get(url, headers=headers, timeout=60)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
({"provider": "deribit"}),
],
)
@pytest.mark.integration
def test_derivatives_futures_instruments(params, headers):
"""Test the futures instruments endpoint."""
params = {p: v for p, v in params.items() if v}

query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/derivatives/futures/instruments?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
({"provider": "deribit", "symbol": "ETH-PERPETUAL"}),
],
)
@pytest.mark.integration
def test_derivatives_futures_info(params, headers):
"""Test the futures info endpoint."""
params = {p: v for p, v in params.items() if v}

query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/derivatives/futures/info?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ def test_derivatives_options_unusual(params, obb):
"expiration": "2025-12",
}
),
(
{
"provider": "deribit",
"interval": "1d",
"symbol": "BTC,ETH",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
],
)
@pytest.mark.integration
Expand All @@ -130,6 +139,7 @@ def test_derivatives_futures_historical(params, obb):
[
({"provider": "yfinance", "symbol": "ES", "date": None}),
({"provider": "cboe", "symbol": "VX", "date": "2024-06-25"}),
({"provider": "deribit", "date": None, "symbol": "BTC", "hours_ago": 12}),
],
)
@pytest.mark.integration
Expand All @@ -147,10 +157,42 @@ def test_derivatives_futures_curve(params, obb):
({"provider": "intrinio", "date": None, "only_traded": True}),
],
)
@pytest.mark.integration
@pytest.mark.skip(
reason="This test is skipped because the download is excessively large."
)
def test_derivatives_options_snapshots(params, obb):
"""Test the options snapshots endpoint."""
result = obb.derivatives.options.snapshots(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
({"provider": "deribit"}),
],
)
@pytest.mark.integration
def test_derivatives_futures_instruments(params, obb):
"""Test the futures instruments endpoint."""
result = obb.derivatives.futures.instruments(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
({"provider": "deribit", "symbol": "ETH-PERPETUAL"}),
],
)
@pytest.mark.integration
def test_derivatives_futures_info(params, obb):
"""Test the futures info endpoint."""
result = obb.derivatives.futures.info(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def derivatives_futures_historical( # noqa: PLR0912
# pylint: disable=import-outside-toplevel
from openbb_charting.charts.price_historical import price_historical

kwargs.update({"candles": False, "same_axis": False})

return price_historical(**kwargs)

@staticmethod
Expand Down Expand Up @@ -107,7 +109,8 @@ def derivatives_futures_curve( # noqa: PLR0912

provider = kwargs.get("provider", "")

df["expiration"] = df["expiration"].apply(to_datetime).dt.strftime("%b-%Y")
if provider != "deribit":
df["expiration"] = df["expiration"].apply(to_datetime).dt.strftime("%b-%Y")

if (
provider == "cboe"
Expand Down Expand Up @@ -163,6 +166,15 @@ def create_fig(figure, df, dates, color_count):
if "date" in df.columns
else ["Current"]
)

if provider == "deribit" and "hours_ago" in df.columns:
dates = [
str(d) + " Hours Ago" if d > 0 else "Current"
for d in df["hours_ago"].unique().tolist()
]
df.loc[:, "date"] = df["hours_ago"].apply(
lambda x: str(x) + " Hours Ago" if x > 0 else "Current"
)
figure, color_count = create_fig(figure, df, dates, color_count)

# Set the title for the chart
Expand All @@ -176,7 +188,7 @@ def create_fig(figure, df, dates, color_count):
)
if len(dates) == 1 and dates[0] != "Current":
title = f"{title} for {dates[0]}"
elif provider == "yfinance":
else:
title = f"{symbol.upper()} Futures Curve"

# Use the supplied title, if any.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,38 @@ async def curve(
) -> OBBject:
"""Futures Term Structure, current or historical."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="FuturesInstruments",
examples=[
APIEx(parameters={"provider": "deribit"}),
],
)
async def instruments(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get reference data for available futures instruments by provider."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="FuturesInfo",
examples=[
APIEx(parameters={"provider": "deribit", "symbol": "BTC"}),
APIEx(parameters={"provider": "deribit", "symbol": "SOLUSDC"}),
APIEx(parameters={"provider": "deribit", "symbol": "SOL_USDC-PERPETUAL"}),
APIEx(parameters={"provider": "deribit", "symbol": "BTC,ETH"}),
],
)
async def info(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get current trading statistics by futures contract symbol."""
return await OBBject.from_query(Query(**locals()))
Loading

0 comments on commit 4bf4821

Please sign in to comment.