Skip to content

Commit

Permalink
[Feature] Add EIA Daily Spot Prices Data via FRED (#6677)
Browse files Browse the repository at this point in the history
* add EIA daily spot prices data via FRED

* line too long

* comment out the test skipped test

* fix test?

* delete commented out sections

* unused argument

* name things like Minh says

---------

Co-authored-by: Igor Radovanovic <[email protected]>
  • Loading branch information
deeleeramone and IgorWounds authored Oct 3, 2024
1 parent c786852 commit b9de848
Show file tree
Hide file tree
Showing 17 changed files with 1,274 additions and 519 deletions.
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

0 comments on commit b9de848

Please sign in to comment.