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 Fred Release Tables #6595

Merged
merged 6 commits into from
Jul 21, 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,73 @@
"""FRED Release Table 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 ReleaseTableQueryParams(QueryParams):
"""FRED Release Table Query."""

release_id: str = Field(
description="The ID of the release." + " Use `fred_search` to find releases.",
)
element_id: Optional[str] = Field(
default=None,
description="The element ID of a specific table in the release.",
)
date: Optional[Union[dateType, str]] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("date", ""),
)


class ReleaseTableData(Data):
"""FRED Release Table Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date", "")
)
level: Optional[int] = Field(
default=None,
description="The indentation level of the element.",
)
element_type: Optional[str] = Field(
default=None,
description="The type of the element.",
)
line: Optional[int] = Field(
default=None,
description="The line number of the element.",
)
element_id: Optional[str] = Field(
default=None,
description="The element id in the parent/child relationship.",
)
parent_id: Optional[str] = Field(
default=None,
description="The parent id in the parent/child relationship.",
)
children: Optional[str] = Field(
default=None,
description="The element_id of each child, as a comma-separated string.",
)
symbol: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
name: Optional[str] = Field(
default=None,
description="The name of the series.",
)
value: Optional[float] = Field(
default=None,
description="The reported value of the series.",
)
33 changes: 33 additions & 0 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,36 @@ def test_economy_pce(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"provider": "fred",
"date": None,
"release_id": "14",
"element_id": "7930",
}
),
(
{
"provider": "fred",
"date": None,
"release_id": "14",
"element_id": None,
}
),
],
)
@pytest.mark.integration
def test_economy_fred_release_table(params, headers):
"""Test the economy fred release table"""
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/fred_release_table?{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 @@ -955,3 +955,35 @@ def test_economy_pce(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"provider": "fred",
"date": None,
"release_id": "14",
"element_id": "7930",
}
),
(
{
"provider": "fred",
"date": None,
"release_id": "14",
"element_id": None,
}
),
],
)
@pytest.mark.integration
def test_economy_fred_release_table(params, obb):
"""Test the economy fred release table endpoint"""
params = {p: v for p, v in params.items() if v}

result = obb.economy.fred_release_table(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,33 @@ async def fred_series(
return await OBBject.from_query(Query(**locals()))


@router.command(
model="FredReleaseTable",
examples=[
APIEx(
description="Get the top-level elements of a release by not supplying an element ID.",
parameters={"release_id": "50", "provider": "fred"},
),
APIEx(
description="Drill down on a specific section of the release.",
parameters={"release_id": "50", "element_id": "4880", "provider": "fred"},
),
APIEx(
description="Drill down on a specific table of the release.",
parameters={"release_id": "50", "element_id": "4881", "provider": "fred"},
),
],
)
async def fred_release_table(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get economic release data by ID and/or element from FRED."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="MoneyMeasures",
examples=[
Expand Down
159 changes: 159 additions & 0 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -5738,6 +5738,165 @@
},
"model": "FredSeries"
},
"/economy/fred_release_table": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Get economic release data by ID and/or element from FRED.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\n# Get the top-level elements of a release by not supplying an element ID.\nobb.economy.fred_release_table(release_id='50', provider='fred')\n# Drill down on a specific section of the release.\nobb.economy.fred_release_table(release_id='50', element_id='4880', provider='fred')\n# Drill down on a specific table of the release.\nobb.economy.fred_release_table(release_id='50', element_id='4881', provider='fred')\n```\n\n",
"parameters": {
"standard": [
{
"name": "release_id",
"type": "str",
"description": "The ID of the release. Use `fred_search` to find releases.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "element_id",
"type": "str",
"description": "The element ID of a specific table in the release.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "date",
"type": "Union[Union[Union[str, date], str], List[Union[Union[str, date], str]]]",
"description": "A specific date to get data for. Multiple items allowed for provider(s): fred.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "provider",
"type": "Literal['fred']",
"description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: fred.",
"default": null,
"optional": true
}
],
"fred": []
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[FredReleaseTable]",
"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": "date",
"description": "The date of the data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "level",
"type": "int",
"description": "The indentation level of the element.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "element_type",
"type": "str",
"description": "The type of the element.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "line",
"type": "int",
"description": "The line number of the element.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "element_id",
"type": "str",
"description": "The element id in the parent/child relationship.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "parent_id",
"type": "str",
"description": "The parent id in the parent/child relationship.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "children",
"type": "str",
"description": "The element_id of each child, as a comma-separated string.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "symbol",
"type": "str",
"description": "The date of the data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "name",
"type": "str",
"description": "The name of the series.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "The reported value of the series.",
"default": null,
"optional": true,
"choices": null
}
],
"fred": []
},
"model": "FredReleaseTable"
},
"/economy/money_measures": {
"deprecated": {
"flag": null,
Expand Down
Loading
Loading