Fix econcal endpoint (#5567)

* fix econcal for python interface

* fix econcal tests

* fix non supported json output
This commit is contained in:
Henrique Joaquim
2023-10-16 16:43:04 +01:00
committed by GitHub
parent f6eac35f0b
commit 08549aad58
8 changed files with 46 additions and 28 deletions

View File

@@ -281,7 +281,7 @@ def test_economy_index_search(params, headers):
@pytest.mark.parametrize(
"params",
[({"region": "US"})],
[({"provider": "cboe", "region": "US"})],
)
@pytest.mark.integration
def test_economy_index_snapshots(params, headers):
@@ -480,11 +480,12 @@ def test_economy_gdpforecast(params, headers):
[
(
{
"provider": "tradingeconomics",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"country": "Portugal",
"country": "portugal",
"group": "gdp",
"importance": 3,
"importance": "Low",
}
)
],

View File

@@ -444,9 +444,9 @@ def test_economy_gdpforecast(params, obb):
{
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"country": "Portugal",
"importance": 1,
"group": "money",
"country": "portugal",
"importance": "Low",
"group": "gdp",
}
),
],

View File

@@ -197,7 +197,7 @@ def gdpforecast(
return OBBject(results=Query(**locals()).execute())
@router.command(model="EconCal")
@router.command(model="EconomicCalendar")
def econcal(
cc: CommandContext,
provider_choices: ProviderChoices,

View File

@@ -161,7 +161,8 @@ def build_api_wrapper(
execute = partial(command_runner.run, path, user_settings)
output: OBBject = execute(*args, **kwargs)
return validate_output(output)
output = validate_output(output)
return output
return wrapper

View File

@@ -7,7 +7,7 @@ from datetime import (
)
from typing import List, Literal, Optional, Union
from pydantic import Field
from pydantic import Field, field_validator
from openbb_provider.abstract.data import Data
from openbb_provider.abstract.query_params import QueryParams
@@ -25,26 +25,24 @@ class EconomicCalendarQueryParams(QueryParams):
default=None,
description=QUERY_DESCRIPTIONS.get("end_date", ""),
)
importance: Optional[Literal[1, 2, 3]] = Field(
importance: Literal["Low", "Medium", "High"] = Field(
default=None,
description="Importance of the event. 1-Low, 2-Medium, 3-High",
description="Importance of the event.",
)
group: Optional[
Literal[
"interest rate",
"inflation",
"bonds",
"consumer",
"gdp",
"government",
"housing",
"labour",
"markets",
"money",
"prices",
"trade",
"business",
]
group: Literal[
"interest rate",
"inflation",
"bonds",
"consumer",
"gdp",
"government",
"housing",
"labour",
"markets",
"money",
"prices",
"trade",
"business",
] = Field(default=None, description="Grouping of events")
# TODO: Probably want to figure out the list we can use.
country: Optional[Union[str, List[str]]] = Field(
@@ -52,6 +50,12 @@ class EconomicCalendarQueryParams(QueryParams):
description="Country of the event",
)
@field_validator("importance")
@classmethod
def importance_to_number(cls, v):
string_to_value = {"Low": 1, "Medium": 2, "High": 3}
return string_to_value[v]
class EconomicCalendarData(Data):
"""Economic calendar Data."""

View File

@@ -128,9 +128,14 @@ class CboeIndexSnapshotsFetcher(
data = data[list(EUR_INDEX_COLUMNS.keys())]
data.columns = list(EUR_INDEX_COLUMNS.values())
data["change_percent"] = data["change_percent"].fillna(0.0)
return data.reset_index().to_dict("records")
@staticmethod
def transform_data(data: dict) -> List[CboeIndexSnapshotsData]:
"""Transform the data to the standard format"""
for item in data:
item["name"] = item["name"].replace("/", "-")
return [CboeIndexSnapshotsData.model_validate(d) for d in data]

View File

@@ -7,5 +7,5 @@ tradingeconomics_provider = Provider(
website="https://tradingeconomics.com/",
description="""Trading Economics""",
required_credentials=["api_key"],
fetcher_dict={"EconCal": TEEarningsCalendarFetcher},
fetcher_dict={"EconomicCalendar": TEEarningsCalendarFetcher},
)

View File

@@ -74,5 +74,12 @@ def generate_url(in_query):
# Group + Date
elif check_args(query, ["group", "start_date", "end_date"]):
url = f'{base_url}/group/{query["group"]}/{query["start_date"]}/{query["end_date"]}?c='
# All fields
elif check_args(
query, ["country", "group", "importance", "start_date", "end_date"]
):
start_date = query["start_date"]
end_date = query["end_date"]
url = f"{base_url}/country/{country}/group/{group}/{start_date}/{end_date}?{urlencode(query)}&c="
return url if url else ""