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 Provider & Weekly Petroleum Status Report #6693

Merged
merged 38 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
35492f8
add eia provider and weekly petroleum status report
deeleeramone Sep 25, 2024
9cbfc4f
codespell
deeleeramone Sep 25, 2024
3d4e108
sort imports
deeleeramone Sep 25, 2024
ce20839
lint and update lock
deeleeramone Sep 25, 2024
64184a8
move raise up in try block
deeleeramone Sep 25, 2024
dca5be9
Merge branch 'develop' into feature/eia-provider
deeleeramone Sep 26, 2024
3515239
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 3, 2024
4923513
add STEO
deeleeramone Oct 6, 2024
293dc24
static files
deeleeramone Oct 6, 2024
04b4902
steo tests
deeleeramone Oct 6, 2024
69a6cf6
linting
deeleeramone Oct 6, 2024
61d5e04
mypy
deeleeramone Oct 7, 2024
04cd549
readme and docstring grammar police
deeleeramone Oct 7, 2024
f4d7d41
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 7, 2024
477185b
merge branch develop
deeleeramone Oct 8, 2024
2e5fc29
fix test..?
deeleeramone Oct 10, 2024
def12c0
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 14, 2024
2ea9930
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 18, 2024
35d0818
add symbol field to steo
deeleeramone Oct 19, 2024
d0c6dad
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBB in…
deeleeramone Oct 19, 2024
390705f
static files
deeleeramone Oct 19, 2024
7c59c88
update integration test
deeleeramone Oct 19, 2024
7ecc900
mypy
deeleeramone Oct 19, 2024
d269eb0
pylint
deeleeramone Oct 19, 2024
0504d50
fix test..?
deeleeramone Oct 19, 2024
2a45696
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 21, 2024
5175dde
undo attempt to fix test
deeleeramone Oct 21, 2024
20d5463
add empty init file
deeleeramone Oct 21, 2024
fffdb1f
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 21, 2024
7681728
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 22, 2024
f3d738a
add empty init file
deeleeramone Oct 22, 2024
79012ca
change package name so the tests don't fail
deeleeramone Oct 22, 2024
70e8010
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 23, 2024
f23ca41
Merge branch 'develop' into feature/eia-provider
deeleeramone Oct 24, 2024
ae85166
merge branch develop
deeleeramone Oct 28, 2024
7cc28ed
some updates
deeleeramone Oct 28, 2024
4fe7713
lint
deeleeramone Oct 28, 2024
fda7c98
Merge branch 'develop' into feature/eia-provider
piiq Oct 31, 2024
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,40 @@
"""Petroleum Status Report Standard Model."""

from datetime import date as dateType
from typing import Optional, Union

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 PetroleumStatusReportQueryParams(QueryParams):
"""Petroleum Status Report 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 PetroleumStatusReportData(Data):
"""Petroleum Status Report Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
table: Optional[str] = Field(description="Table name for the data.")
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
order: Optional[int] = Field(
default=None, description="Presented order of the data, relative to the table."
)
title: Optional[str] = Field(default=None, description="Title of the data.")
value: Union[int, float] = Field(description="Value of the data.")
unit: Optional[str] = Field(default=None, description="Unit or scale of the data.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Short Term Energy Outlook Standard Model."""

from datetime import date as dateType
from typing import Optional, Union

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 ShortTermEnergyOutlookQueryParams(QueryParams):
"""Short Term Energy Outlook 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 ShortTermEnergyOutlookData(Data):
"""Short Term Energy Outlook Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
table: Optional[str] = Field(default=None, description="Table name for the data.")
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
order: Optional[int] = Field(
default=None, description="Presented order of the data, relative to the table."
)
title: Optional[str] = Field(default=None, description="Title of the data.")
value: Union[int, float] = Field(description="Value of the data.")
unit: Optional[str] = Field(default=None, description="Unit or scale of the data.")
1 change: 1 addition & 0 deletions openbb_platform/dev_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
openbb-sec = { path = "./providers/sec", develop = true }
openbb-tiingo = { path = "./providers/tiingo", develop = true }
openbb-tradingeconomics = { path = "./providers/tradingeconomics", develop = true }
openbb-us-eia = { path = "./providers/eia", develop = true }
openbb-yfinance = { path = "./providers/yfinance", develop = true }

openbb-commodity = { path = "./extensions/commodity", develop = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,67 @@ def test_commodity_price_spot(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
(
{
"category": "balance_sheet",
"table": "stocks",
"start_date": None,
"end_date": None,
"provider": "eia",
"use_cache": True,
}
),
(
{
"category": "weekly_estimates",
"table": "crude_production",
"start_date": "2020-01-01",
"end_date": "2023-12-31",
"provider": "eia",
"use_cache": True,
}
),
],
)
@pytest.mark.integration
def test_commodity_petroleum_status_report(params, headers):
"""Test the Petroleum Status Report 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/petroleum_status_report?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
(
{
"table": "01",
"symbol": None,
"start_date": "2024-09-01",
"end_date": "2024-10-01",
"provider": "eia",
"frequency": "month",
}
),
],
)
@pytest.mark.integration
def test_commodity_short_term_energy_outlook(params, headers):
"""Test the Short Term Energy Outlook 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/short_term_energy_outlook?{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 @@ -40,3 +40,61 @@ def test_commodity_price_spot(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[
(
{
"category": "balance_sheet",
"table": "stocks",
"start_date": None,
"end_date": None,
"provider": "eia",
"use_cache": True,
}
),
(
{
"category": "weekly_estimates",
"table": "crude_production",
"start_date": "2020-01-01",
"end_date": "2023-12-31",
"provider": "eia",
"use_cache": True,
}
),
],
)
@pytest.mark.integration
def test_commodity_petroleum_status_report(params, obb):
"""Test Commodity Petroleum Status Report endpoint."""
result = obb.commodity.petroleum_status_report(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[
(
{
"table": "01",
"symbol": None,
"start_date": "2024-09-01",
"end_date": "2024-10-01",
"provider": "eia",
"frequency": "month",
}
),
],
)
@pytest.mark.integration
def test_commodity_short_term_energy_outlook(params, obb):
"""Test Commodity Short Term Energy Outlook endpoint."""
result = obb.commodity.short_term_energy_outlook(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# pylint: disable=unused-argument,unused-import
# flake8: noqa: F401

# 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 @@ -20,3 +22,59 @@


router.include_router(price_router)


@router.command(
model="PetroleumStatusReport",
examples=[
APIEx(
description="Get the EIA's Weekly Petroleum Status Report.",
parameters={"provider": "eia"},
),
APIEx(
description="Select the category of data, and filter for a specific table within the report.",
parameters={
"category": "weekly_estimates",
"table": "imports",
"provider": "eia",
},
),
],
)
async def petroleum_status_report(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""EIA Weekly Petroleum Status Report."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="ShortTermEnergyOutlook",
examples=[
APIEx(
description="Get the EIA's Short Term Energy Outlook.",
parameters={"provider": "eia"},
),
APIEx(
description="Select the specific table of data from the STEO. Table 03d is World Crude Oil Production.",
parameters={
"table": "03d",
"provider": "eia",
},
),
],
)
async def short_term_energy_outlook(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Monthly short term (18 month) projections using EIA's STEO model.

Source: www.eia.gov/steo/
"""
return await OBBject.from_query(Query(**locals()))
Loading
Loading