summaryrefslogtreecommitdiffstats
path: root/openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py
diff options
context:
space:
mode:
Diffstat (limited to 'openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py')
-rw-r--r--openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py b/openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py
index 97e1056633b..ec3d2ffac08 100644
--- a/openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py
+++ b/openbb_platform/providers/tradingeconomics/openbb_tradingeconomics/models/economic_calendar.py
@@ -2,6 +2,7 @@
from datetime import datetime
from typing import Any, Dict, List, Literal, Optional, Union
+from warnings import warn
from openbb_core.provider.abstract.fetcher import Fetcher
from openbb_core.provider.standard_models.economic_calendar import (
@@ -31,6 +32,7 @@ GROUPS = Literal[
"trade",
"business",
]
+TE_COUNTRY_LIMIT = 28
class TEEconomicCalendarQueryParams(EconomicCalendarQueryParams):
@@ -48,6 +50,8 @@ class TEEconomicCalendarQueryParams(EconomicCalendarQueryParams):
)
group: Optional[GROUPS] = Field(default=None, description="Grouping of events")
+ _number_of_countries: int = 0
+
@field_validator("country", mode="before", check_fields=False)
@classmethod
def validate_country(cls, c: str): # pylint: disable=E0213
@@ -57,6 +61,13 @@ class TEEconomicCalendarQueryParams(EconomicCalendarQueryParams):
for v in values:
check_item(v.lower(), COUNTRIES)
result.append(v.lower())
+
+ cls._number_of_countries = len(result)
+ if cls._number_of_countries >= TE_COUNTRY_LIMIT:
+ warn(
+ f"Trading Economics API tend to fail if the number of countries is above {TE_COUNTRY_LIMIT}."
+ )
+
return ",".join(result)
@field_validator("importance")
@@ -130,11 +141,15 @@ class TEEconomicCalendarFetcher(
async def callback(response: ClientResponse, _: Any) -> Union[dict, List[dict]]:
"""Return the response."""
if response.status != 200:
- raise RuntimeError(f"Error in TE request -> {await response.text()}")
+ raise RuntimeError(
+ f"Error in TE request: \n{await response.text()}"
+ f"\nInfo -> TE API tend to fail if the number of countries is above {TE_COUNTRY_LIMIT}."
+ )
return await response.json()
return await amake_request(url, response_callback=callback, **kwargs)
+ # pylint: disable=unused-argument
@staticmethod
def transform_data(
query: TEEconomicCalendarQueryParams, data: List[Dict], **kwargs: Any