Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add EIA Daily Spot Prices Data via FRED #6677

Merged
merged 15 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Commodity Spot Prices Standard Model."""

from datetime import (
date as dateType,
)
from typing import Optional

from pydantic import Field

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,
QUERY_DESCRIPTIONS,
)


class CommoditySpotPricesQueryParams(QueryParams):
"""Commodity Spot Prices Query."""

start_date: Optional[dateType] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("start_date", ""),
)
end_date: Optional[dateType] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("end_date", ""),
)


class CommoditySpotPricesData(Data):
"""Commodity Spot Prices Data."""

date: dateType = Field(
description=DATA_DESCRIPTIONS.get("date", ""),
)
symbol: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
commodity: Optional[str] = Field(
default=None,
description="Commodity name.",
)
price: float = Field(
description="Price of the commodity.",
json_schema_extra={"x-unit_measurement": "currency"},
)
unit: Optional[str] = Field(
default=None,
description="Unit of the commodity price.",
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,24 @@ def headers():
[
(
{
"asset": "gold",
"commodity": "all",
"start_date": None,
"end_date": None,
"collapse": None,
"frequency": None,
"transform": None,
"provider": "nasdaq",
}
),
(
{
"asset": "silver",
"start_date": "1990-01-01",
"end_date": "2023-01-01",
"collapse": "monthly",
"transform": "diff",
"provider": "nasdaq",
"aggregation_method": None,
"provider": "fred",
}
),
],
)
@pytest.mark.integration
def test_commodity_lbma_fixing(params, headers):
"""Test the LBMA fixing endpoint."""
def test_commodity_price_spot(params, headers):
"""Test the commodity spot prices 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/commodity/lbma_fixing?{query_str}"
url = f"http://0.0.0.0:8000/api/v1/commodity/price/spot?{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 @@ -20,32 +20,23 @@ def obb(pytestconfig): # pylint: disable=inconsistent-return-statements
[
(
{
"asset": "gold",
"commodity": "all",
"start_date": None,
"end_date": None,
"collapse": None,
"frequency": None,
"transform": None,
"provider": "nasdaq",
}
),
(
{
"asset": "silver",
"start_date": "1990-01-01",
"end_date": "2023-01-01",
"collapse": "monthly",
"transform": "diff",
"provider": "nasdaq",
"aggregation_method": None,
"provider": "fred",
}
),
],
)
@pytest.mark.integration
def test_commodity_lbma_fixing(params, obb):
"""Test the LBMA fixing endpoint."""
def test_commodity_price_spot(params, obb):
"""Test the commodity spot prices endpoint."""
params = {p: v for p, v in params.items() if v}

result = obb.commodity.lbma_fixing(**params)
result = obb.commodity.price.spot(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""The Commodity router."""

# pylint: disable=unused-argument,unused-import
# flake8: noqa: F401

from openbb_core.app.model.command_context import CommandContext
from openbb_core.app.model.example import APIEx
from openbb_core.app.model.obbject import OBBject
Expand All @@ -11,32 +14,9 @@
from openbb_core.app.query import Query
from openbb_core.app.router import Router

from openbb_commodity.price.price_router import router as price_router

router = Router(prefix="", description="Commodity market data.")


# pylint: disable=unused-argument
@router.command(
model="LbmaFixing",
examples=[
APIEx(parameters={"provider": "nasdaq"}),
APIEx(
description="Get the daily LBMA fixing prices for silver in 2023.",
parameters={
"asset": "silver",
"start_date": "2023-01-01",
"end_date": "2023-12-31",
"transform": "rdiff",
"collapse": "monthly",
"provider": "nasdaq",
},
),
],
)
async def lbma_fixing(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Daily LBMA Fixing Prices in USD/EUR/GBP."""
return await OBBject.from_query(Query(**locals()))
router.include_router(price_router)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Commodity Price."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Price Router."""

# pylint: disable=unused-argument

from openbb_core.app.model.command_context import CommandContext
from openbb_core.app.model.example import APIEx
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.provider_interface import (
ExtraParams,
ProviderChoices,
StandardParams,
)
from openbb_core.app.query import Query
from openbb_core.app.router import Router

router = Router(prefix="/price")


@router.command(
model="CommoditySpotPrices",
examples=[
APIEx(parameters={"provider": "fred"}),
APIEx(parameters={"provider": "fred", "commodity": "wti"}),
],
)
async def spot(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Commodity Spot Prices."""
return await OBBject.from_query(Query(**locals()))
Loading
Loading