summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <henriquecjoaquim@gmail.com>2024-04-23 15:06:29 +0100
committerGitHub <noreply@github.com>2024-04-23 14:06:29 +0000
commit9bfa378022673fff014cb8ab2af2e8de1b2ee78d (patch)
tree3b50c3c80ee4a40e324233cd2719f7cda6e90d07
parent99b8597392a2a1af5a9cb303d6c37375aac6605a (diff)
[Feature] Warn limit number of countries in TE request (#6334)
* limit number of countries in TE request * const * disable=unused-argument * warn and info when countries above 28 --------- Co-authored-by: hjoaquim <h.joaquim@campus.fct.unl.pt> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
-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