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 Nonfarm Payrolls To economy.survey #6571

Merged
merged 6 commits into from
Jul 10, 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,31 @@
"""NonFarm Payrolls 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 NonFarmPayrollsQueryParams(QueryParams):
"""NonFarm Payrolls Query."""

date: Optional[Union[dateType, str]] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("date", "")
+ " Default is the latest report.",
)


class NonFarmPayrollsData(Data):
"""NonFarm Payrolls Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
value: float = Field(description=DATA_DESCRIPTIONS.get("value", ""))
24 changes: 24 additions & 0 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,3 +949,27 @@ def test_economy_primary_dealer_positioning(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": "2024-06-01,2023-06-01",
"category": "avg_earnings_hourly",
}
),
],
)
@pytest.mark.integration
def test_economy_survey_nonfarm_payrolls(params, headers):
"""Test the economy survey nonfarm payrolls 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/economy/survey/nonfarm_payrolls?{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 @@ -898,3 +898,26 @@ def test_economy_primary_dealer_positioning(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"provider": "fred",
"date": "2024-06-01,2023-06-01",
"category": "avg_earnings_hourly",
}
),
],
)
@pytest.mark.integration
def test_economy_survey_nonfarm_payrolls(params, obb):
"""Test the economy survery nonfarm payrolls endpoint"""
params = {p: v for p, v in params.items() if v}

result = obb.economy.survey.nonfarm_payrolls(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ async def manufacturing_outlook_texas(
) -> OBBject:
"""Get The Manufacturing Outlook Survey For The Texas Region."""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="NonFarmPayrolls",
examples=[
APIEx(parameters={"provider": "fred"}),
APIEx(
parameters={
"category": "avg_hours",
"provider": "fred",
}
),
],
)
async def nonfarm_payrolls(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get Nonfarm Payrolls Survey."""
return await OBBject.from_query(Query(**locals()))
155 changes: 155 additions & 0 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -3490,6 +3490,161 @@
},
"model": "ManufacturingOutlookTexas"
},
"/economy/survey/nonfarm_payrolls": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Get Nonfarm Payrolls Survey.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.survey.nonfarm_payrolls(provider='fred')\nobb.economy.survey.nonfarm_payrolls(category=avg_hours, provider='fred')\n```\n\n",
"parameters": {
"standard": [
{
"name": "date",
"type": "Union[Union[Union[str, date], str], List[Union[Union[str, date], str]]]",
"description": "A specific date to get data for. Default is the latest report. 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": [
{
"name": "category",
"type": "Literal['employees_nsa', 'employees_sa', 'employees_production_and_nonsupervisory', 'employees_women', 'employees_women_percent', 'avg_hours', 'avg_hours_production_and_nonsupervisory', 'avg_hours_overtime', 'avg_hours_overtime_production_and_nonsupervisory', 'avg_earnings_hourly', 'avg_earnings_hourly_production_and_nonsupervisory', 'avg_earnings_weekly', 'avg_earnings_weekly_production_and_nonsupervisory', 'index_weekly_hours', 'index_weekly_hours_production_and_nonsupervisory', 'index_weekly_payrolls', 'index_weekly_payrolls_production_and_nonsupervisory']",
"description": "The category to query.",
"default": "employees_nsa",
"optional": true,
"choices": [
"employees_nsa",
"employees_sa",
"employees_production_and_nonsupervisory",
"employees_women",
"employees_women_percent",
"avg_hours",
"avg_hours_production_and_nonsupervisory",
"avg_hours_overtime",
"avg_hours_overtime_production_and_nonsupervisory",
"avg_earnings_hourly",
"avg_earnings_hourly_production_and_nonsupervisory",
"avg_earnings_weekly",
"avg_earnings_weekly_production_and_nonsupervisory",
"index_weekly_hours",
"index_weekly_hours_production_and_nonsupervisory",
"index_weekly_payrolls",
"index_weekly_payrolls_production_and_nonsupervisory"
]
}
]
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[NonFarmPayrolls]",
"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": "",
"optional": false,
"choices": null
},
{
"name": "symbol",
"type": "str",
"description": "Symbol representing the entity requested in the data.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "",
"default": "",
"optional": false,
"choices": null
}
],
"fred": [
{
"name": "name",
"type": "str",
"description": "The name of the series.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "element_id",
"type": "str",
"description": "The element id in the parent/child relationship.",
"default": "",
"optional": false,
"choices": null
},
{
"name": "parent_id",
"type": "str",
"description": "The parent id in the parent/child relationship.",
"default": "",
"optional": false,
"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": "level",
"type": "int",
"description": "The indentation level of the element.",
"default": "",
"optional": false,
"choices": null
}
]
},
"model": "NonFarmPayrolls"
},
"/economy/calendar": {
"deprecated": {
"flag": null,
Expand Down
2 changes: 2 additions & 0 deletions openbb_platform/providers/fred/openbb_fred/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from openbb_fred.models.moody import FREDMoodyCorporateBondIndexFetcher
from openbb_fred.models.mortgage_indices import FredMortgageIndicesFetcher
from openbb_fred.models.non_farm_payrolls import FredNonFarmPayrollsFetcher
from openbb_fred.models.overnight_bank_funding_rate import (
FredOvernightBankFundingRateFetcher,
)
Expand Down Expand Up @@ -75,6 +76,7 @@
"ManufacturingOutlookTexas": FredManufacturingOutlookTexasFetcher,
"MoodyCorporateBondIndex": FREDMoodyCorporateBondIndexFetcher,
"MortgageIndices": FredMortgageIndicesFetcher,
"NonFarmPayrolls": FredNonFarmPayrollsFetcher,
"OvernightBankFundingRate": FredOvernightBankFundingRateFetcher,
"CommercialPaper": FREDCommercialPaperFetcher,
"FredSearch": FredSearchFetcher,
Expand Down
Loading
Loading