Skip to content

Commit

Permalink
Merge branch 'develop' into feature/validate-command-kwarg
Browse files Browse the repository at this point in the history
  • Loading branch information
deeleeramone authored Jan 8, 2025
2 parents f105050 + a6d01da commit 12a1024
Show file tree
Hide file tree
Showing 29 changed files with 5,469 additions and 972 deletions.
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."""
904 changes: 437 additions & 467 deletions openbb_platform/core/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion openbb_platform/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packages = [{ include = "openbb_core" }]
[tool.poetry.dependencies]
python = "^3.9"
uvicorn = "^0.32.0"
websockets = "^13.0"
websockets = "^14.0"
pandas = ">=1.5.3"
html5lib = "^1.1"
fastapi = "^0.115"
Expand Down
4 changes: 2 additions & 2 deletions openbb_platform/dev_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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 @@ -192,7 +192,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()))
33 changes: 33 additions & 0 deletions openbb_platform/providers/deribit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,36 @@
- SOL
- BNB
- PAXG
- obb.derivatives.futures.curve
- Support for symbols:
- BTC
- ETH
- PAXG
- obb.derivatives.futures.historical
- Support for symbols (Perpetual Futures):
- ADAUSDC
- ALGOUSDC
- AVAXUSDC
- BCHUSDC
- BNBUSDC
- BTC
- BTCUSDC
- BTCUSDT
- DOGEUSDC
- DOTUSDC
- ETH
- ETHUSDC
- ETHUSDT
- LINKUSDC
- LTCUSDC
- NEARUSDC
- PAXGUSDC
- SOLUSDC
- TRXUSDC
- UNIUSDC
- XRPUSDC
- Additional symbols include all Deribit instrument names of current open contracts for BTC, ETH, and PAXG futures.
- obb.derivatives.futures.instruments
- Reference data for all current futures instruments.
- obb.derivatives.futures.info
- Key stats by symbol (multiple items allowed).
13 changes: 11 additions & 2 deletions openbb_platform/providers/deribit/openbb_deribit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
"""OpenBB Deribit Provider Module."""

from openbb_core.provider.abstract.provider import Provider

from openbb_deribit.models.futures_curve import DeribitFuturesCurveFetcher
from openbb_deribit.models.futures_historical import DeribitFuturesHistoricalFetcher
from openbb_deribit.models.futures_info import DeribitFuturesInfoFetcher
from openbb_deribit.models.futures_instruments import DeribitFuturesInstrumentsFetcher
from openbb_deribit.models.options_chains import DeribitOptionsChainsFetcher

deribit_provider = Provider(
name="deribit",
website="https://deribit.com/",
description="""Unofficial Python client for public data published by Deribit.""",
credentials=None,
fetcher_dict={"OptionsChains": DeribitOptionsChainsFetcher},
fetcher_dict={
"FuturesCurve": DeribitFuturesCurveFetcher,
"FuturesHistorical": DeribitFuturesHistoricalFetcher,
"FuturesInfo": DeribitFuturesInfoFetcher,
"FuturesInstruments": DeribitFuturesInstrumentsFetcher,
"OptionsChains": DeribitOptionsChainsFetcher,
},
repr_name="Deribit Public Data",
instructions="This provider does not require any credentials and is not meant for trading.",
)
Loading

0 comments on commit 12a1024

Please sign in to comment.