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 Retail Prices to Economy #6474

Merged
merged 7 commits into from
Jun 2, 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,56 @@
"""Retail 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 RetailPricesQueryParams(QueryParams):
"""Retail Prices Query."""

item: Optional[str] = Field(
default=None,
description="The item or basket of items to query.",
)
country: str = Field(
description=QUERY_DESCRIPTIONS.get("country", ""),
default="united_states",
)
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 RetailPricesData(Data):
"""Retail Prices Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
symbol: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
country: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("country", ""),
)
description: str = Field(
default=None,
description="Description of the item.",
)
value: Optional[float] = Field(
default=None,
description="Price, or change in price, per unit.",
)
29 changes: 29 additions & 0 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,3 +786,32 @@ def test_economy_immediate_interest_rate(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"country": "united_states",
"item": "meats",
"region": "all_city",
"frequency": "annual",
"provider": "fred",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
"transform": "pc1",
}
),
],
)
@pytest.mark.integration
def test_economy_retail_prices(params, headers):
"""Test the economy retail_prices."""
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/economy/retail_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 @@ -743,3 +743,31 @@ def test_economy_immediate_interest_rate(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"country": "united_states",
"item": "meats",
"region": "all_city",
"frequency": "annual",
"provider": "fred",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
"transform": "pc1",
}
),
],
)
@pytest.mark.integration
def test_economy_retail_prices(params, obb):
"""Test economy retail prices."""
params = {p: v for p, v in params.items() if v}

result = obb.economy.retail_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 @@ -483,3 +483,35 @@ async def immediate_interest_rate(
) -> OBBject:
"""Get immediate interest rates by country."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="RetailPrices",
examples=[
APIEx(parameters={"provider": "fred"}),
APIEx(
description="The price of eggs in the northeast census region.",
parameters={
"item": "eggs",
"region": "northeast",
"provider": "fred",
},
),
APIEx(
description="The percentage change in price, from one-year ago, of various meats, US City Average.",
parameters={
"item": "meats",
"transform": "pc1",
"provider": "fred",
},
),
],
)
async def retail_prices(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get retail prices for common items."""
return await OBBject.from_query(Query(**locals()))
Loading
Loading