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 5 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 @@ -20,38 +20,66 @@ def headers():
return {"Authorization": f"Basic {base64_bytes.decode('ascii')}"}


# @pytest.mark.parametrize(
# "params",
# [
# (
# {
# "asset": "gold",
# "start_date": None,
# "end_date": None,
# "collapse": None,
# "transform": None,
# "provider": "nasdaq",
# }
# ),
# (
# {
# "asset": "silver",
# "start_date": "1990-01-01",
# "end_date": "2023-01-01",
# "collapse": "monthly",
# "transform": "diff",
# "provider": "nasdaq",
# }
# ),
# ],
# )
# @pytest.mark.skip(reason="Resource no longer available. Pending replacement/removal.")
# def test_commodity_lbma_fixing(params, headers):
deeleeramone marked this conversation as resolved.
Show resolved Hide resolved
# """Test the LBMA fixing 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}"
# result = requests.get(url, headers=headers, timeout=10)
# assert isinstance(result, requests.Response)
# assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
(
{
"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_spot_prices(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/spot_prices?{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 @@ -15,37 +15,64 @@ def obb(pytestconfig): # pylint: disable=inconsistent-return-statements
return openbb.obb


# @pytest.mark.parametrize(
# "params",
# [
# (
# {
# "asset": "gold",
# "start_date": None,
# "end_date": None,
# "collapse": None,
# "transform": None,
# "provider": "nasdaq",
# }
# ),
# (
# {
# "asset": "silver",
# "start_date": "1990-01-01",
# "end_date": "2023-01-01",
# "collapse": "monthly",
# "transform": "diff",
# "provider": "nasdaq",
# }
# ),
# ],
# )
# @pytest.mark.skip(reason="Resource no longer available. Pending replacement/removal.")
# def test_commodity_lbma_fixing(params, obb):
# """Test the LBMA fixing endpoint."""
# params = {p: v for p, v in params.items() if v}
#
# result = obb.commodity.lbma_fixing(**params)
# assert result
# assert isinstance(result, OBBject)
# assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[
(
{
"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_spot_prices(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.spot_prices(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,45 @@


# 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.command(
model="LbmaFixing",
model="CommoditySpotPrices",
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",
},
),
APIEx(parameters={"provider": "fred"}),
APIEx(parameters={"provider": "fred", "commodity": "wti"}),
],
)
async def lbma_fixing(
async def spot_prices(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Daily LBMA Fixing Prices in USD/EUR/GBP."""
"""Commodity Spot Prices."""
return await OBBject.from_query(Query(**locals()))
Loading
Loading