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 13 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_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 @@ -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_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
@@ -1,5 +1,7 @@
"""The Commodity 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
Expand All @@ -14,29 +16,18 @@
router = Router(prefix="", description="Commodity market data.")


# pylint: disable=unused-argument
@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()))
188 changes: 185 additions & 3 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,185 @@
}
},
"paths": {
"/commodity/spot_prices": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Commodity Spot Prices.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.commodity.spot_prices(provider='fred')\nobb.commodity.spot_prices(provider='fred', commodity=wti)\n```\n\n",
"parameters": {
"standard": [
{
"name": "start_date",
"type": "Union[date, str]",
"description": "Start date of the data, in YYYY-MM-DD format.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "end_date",
"type": "Union[date, str]",
"description": "End date of the data, in YYYY-MM-DD format.",
"default": null,
"optional": true,
"choices": null
}
],
"fred": [
{
"name": "commodity",
"type": "Literal['wti', 'brent', 'natural_gas', 'jet_fuel', 'propane', 'heating_oil', 'diesel_gulf_coast', 'diesel_ny_harbor', 'diesel_la', 'gasoline_ny_harbor', 'gasoline_gulf_coast', 'rbob', 'all']",
"description": "Commodity name associated with the EIA spot price commodity data, default is 'all'.",
"default": "all",
"optional": true,
"choices": [
"wti",
"brent",
"natural_gas",
"jet_fuel",
"propane",
"heating_oil",
"diesel_gulf_coast",
"diesel_ny_harbor",
"diesel_la",
"gasoline_ny_harbor",
"gasoline_gulf_coast",
"rbob",
"all"
]
},
{
"name": "frequency",
"type": "Literal['a', 'q', 'm', 'w', 'd', 'wef', 'weth', 'wew', 'wetu', 'wem', 'wesu', 'wesa', 'bwew', 'bwem']",
"description": "Frequency aggregation to convert high frequency data to lower frequency.\n None = No change\n a = Annual\n q = Quarterly\n m = Monthly\n w = Weekly\n d = Daily\n wef = Weekly, Ending Friday\n weth = Weekly, Ending Thursday\n wew = Weekly, Ending Wednesday\n wetu = Weekly, Ending Tuesday\n wem = Weekly, Ending Monday\n wesu = Weekly, Ending Sunday\n wesa = Weekly, Ending Saturday\n bwew = Biweekly, Ending Wednesday\n bwem = Biweekly, Ending Monday",
"default": null,
"optional": true,
"choices": [
"a",
"q",
"m",
"w",
"d",
"wef",
"weth",
"wew",
"wetu",
"wem",
"wesu",
"wesa",
"bwew",
"bwem"
]
},
{
"name": "aggregation_method",
"type": "Literal['avg', 'sum', 'eop']",
"description": "A key that indicates the aggregation method used for frequency aggregation.\n This parameter has no affect if the frequency parameter is not set.\n avg = Average\n sum = Sum\n eop = End of Period",
"default": "eop",
"optional": true,
"choices": [
"avg",
"sum",
"eop"
]
},
{
"name": "transform",
"type": "Literal['chg', 'ch1', 'pch', 'pc1', 'pca', 'cch', 'cca', 'log']",
"description": "Transformation type\n None = No transformation\n chg = Change\n ch1 = Change from Year Ago\n pch = Percent Change\n pc1 = Percent Change from Year Ago\n pca = Compounded Annual Rate of Change\n cch = Continuously Compounded Rate of Change\n cca = Continuously Compounded Annual Rate of Change\n log = Natural Log",
"default": null,
"optional": true,
"choices": [
"chg",
"ch1",
"pch",
"pc1",
"pca",
"cch",
"cca",
"log"
]
}
]
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[CommoditySpotPrices]",
"description": "Serializable results."
},
{
"name": "provider",
"type": "Optional[Literal['fred']]",
"description": "Provider name."
},
{
"name": "warnings",
"type": "Optional[List[Warning_]]",
"description": "List of warnings."
},
{
"name": "chart",
"type": "Optional[Chart]",
"description": "Chart object."
},
{
"name": "extra",
"type": "Dict[str, Any]",
"description": "Extra info."
}
]
},
"data": {
"standard": [
{
"name": "date",
"type": "Union[date, str]",
"description": "The date of the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "symbol",
"type": "str",
"description": "Symbol representing the entity requested in the data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "commodity",
"type": "str",
"description": "Commodity name.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "price",
"type": "float",
"description": "Price of the commodity.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "unit",
"type": "str",
"description": "Unit of the commodity price.",
"default": null,
"optional": true,
"choices": null
}
],
"fred": []
},
"model": "CommoditySpotPrices"
},
"/crypto/price/historical": {
"deprecated": {
"flag": null,
Expand Down Expand Up @@ -5668,7 +5847,7 @@
{
"name": "frequency",
"type": "Literal['a', 'q', 'm', 'w', 'd', 'wef', 'weth', 'wew', 'wetu', 'wem', 'wesu', 'wesa', 'bwew', 'bwem']",
"description": "Frequency aggregation to convert high frequency data to lower frequency.\n \n None = No change\n \n a = Annual\n \n q = Quarterly\n \n m = Monthly\n \n w = Weekly\n \n d = Daily\n \n wef = Weekly, Ending Friday\n \n weth = Weekly, Ending Thursday\n \n wew = Weekly, Ending Wednesday\n \n wetu = Weekly, Ending Tuesday\n \n wem = Weekly, Ending Monday\n \n wesu = Weekly, Ending Sunday\n \n wesa = Weekly, Ending Saturday\n \n bwew = Biweekly, Ending Wednesday\n \n bwem = Biweekly, Ending Monday",
"description": "Frequency aggregation to convert high frequency data to lower frequency.\n None = No change\n a = Annual\n q = Quarterly\n m = Monthly\n w = Weekly\n d = Daily\n wef = Weekly, Ending Friday\n weth = Weekly, Ending Thursday\n wew = Weekly, Ending Wednesday\n wetu = Weekly, Ending Tuesday\n wem = Weekly, Ending Monday\n wesu = Weekly, Ending Sunday\n wesa = Weekly, Ending Saturday\n bwew = Biweekly, Ending Wednesday\n bwem = Biweekly, Ending Monday",
"default": null,
"optional": true,
"choices": [
Expand All @@ -5691,7 +5870,7 @@
{
"name": "aggregation_method",
"type": "Literal['avg', 'sum', 'eop']",
"description": "A key that indicates the aggregation method used for frequency aggregation.\n This parameter has no affect if the frequency parameter is not set.\n \n avg = Average\n \n sum = Sum\n \n eop = End of Period",
"description": "A key that indicates the aggregation method used for frequency aggregation.\n This parameter has no affect if the frequency parameter is not set.\n avg = Average\n sum = Sum\n eop = End of Period",
"default": "eop",
"optional": true,
"choices": [
Expand All @@ -5703,7 +5882,7 @@
{
"name": "transform",
"type": "Literal['chg', 'ch1', 'pch', 'pc1', 'pca', 'cch', 'cca', 'log']",
"description": "Transformation type\n \n None = No transformation\n \n chg = Change\n \n ch1 = Change from Year Ago\n \n pch = Percent Change\n \n pc1 = Percent Change from Year Ago\n \n pca = Compounded Annual Rate of Change\n \n cch = Continuously Compounded Rate of Change\n \n cca = Continuously Compounded Annual Rate of Change\n \n log = Natural Log",
"description": "Transformation type\n None = No transformation\n chg = Change\n ch1 = Change from Year Ago\n pch = Percent Change\n pc1 = Percent Change from Year Ago\n pca = Compounded Annual Rate of Change\n cch = Continuously Compounded Rate of Change\n cca = Continuously Compounded Annual Rate of Change\n log = Natural Log",
"default": null,
"optional": true,
"choices": [
Expand Down Expand Up @@ -38700,6 +38879,9 @@
}
},
"routers": {
"/commodity": {
"description": "Commodity market data."
},
"/crypto": {
"description": "Cryptocurrency market data."
},
Expand Down
Loading
Loading