mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-25 18:53:26 +00:00
remove trading economics provider (#7578)
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
# OpenBB Trading Economics Provider
|
||||
|
||||
This extension integrates the [Trading Economics](https://docs.tradingeconomics.com/) data provider into the OpenBB SDK.
|
||||
|
||||
## Installation
|
||||
|
||||
To install the extension:
|
||||
|
||||
```bash
|
||||
pip install openbb-tradingeconomics
|
||||
```
|
||||
|
||||
Documentation available [here](https://docs.openbb.co/platform/developer_guide/contributing).
|
||||
@@ -1 +0,0 @@
|
||||
"""OpenBB Trading Economics Provider."""
|
||||
@@ -1,19 +0,0 @@
|
||||
"""Trading Economics provider module."""
|
||||
|
||||
from openbb_core.provider.abstract.provider import Provider
|
||||
from openbb_tradingeconomics.models.economic_calendar import TEEconomicCalendarFetcher
|
||||
|
||||
tradingeconomics_provider = Provider(
|
||||
name="tradingeconomics",
|
||||
website="https://tradingeconomics.com",
|
||||
description="""Trading Economics provides its users with accurate information for
|
||||
196 countries including historical data and forecasts for more than 20 million economic
|
||||
indicators, exchange rates, stock market indexes, government bond yields and commodity
|
||||
prices. Our data for economic indicators is based on official sources, not third party
|
||||
data providers, and our facts are regularly checked for inconsistencies.
|
||||
Trading Economics has received nearly 2 billion page views from all around the
|
||||
world.""",
|
||||
credentials=["api_key"],
|
||||
fetcher_dict={"EconomicCalendar": TEEconomicCalendarFetcher},
|
||||
repr_name="Trading Economics",
|
||||
)
|
||||
@@ -1,266 +0,0 @@
|
||||
"""Trading Economics Economic Calendar Model."""
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
from datetime import (
|
||||
date as dateType,
|
||||
datetime,
|
||||
)
|
||||
from typing import Any, Literal
|
||||
from warnings import warn
|
||||
|
||||
from openbb_core.app.model.abstract.error import OpenBBError
|
||||
from openbb_core.provider.abstract.fetcher import Fetcher
|
||||
from openbb_core.provider.standard_models.economic_calendar import (
|
||||
EconomicCalendarData,
|
||||
EconomicCalendarQueryParams,
|
||||
)
|
||||
from openbb_tradingeconomics.utils.countries import COUNTRIES
|
||||
from pydantic import Field, field_validator, model_validator
|
||||
|
||||
IMPORTANCE_CHOICES = ["low", "medium", "high"]
|
||||
|
||||
IMPORTANCE = Literal["low", "medium", "high"]
|
||||
|
||||
GROUPS_CHOICES = [
|
||||
"interest_rate",
|
||||
"inflation",
|
||||
"bonds",
|
||||
"consumer",
|
||||
"gdp",
|
||||
"government",
|
||||
"housing",
|
||||
"labour",
|
||||
"markets",
|
||||
"money",
|
||||
"prices",
|
||||
"trade",
|
||||
"business",
|
||||
]
|
||||
|
||||
GROUPS = Literal[
|
||||
"interest_rate",
|
||||
"inflation",
|
||||
"bonds",
|
||||
"consumer",
|
||||
"gdp",
|
||||
"government",
|
||||
"housing",
|
||||
"labour",
|
||||
"markets",
|
||||
"money",
|
||||
"prices",
|
||||
"trade",
|
||||
"business",
|
||||
]
|
||||
|
||||
TE_COUNTRY_LIMIT = 28
|
||||
|
||||
|
||||
class TEEconomicCalendarQueryParams(EconomicCalendarQueryParams):
|
||||
"""Trading Economics Economic Calendar Query.
|
||||
|
||||
Source: https://docs.tradingeconomics.com/economic_calendar/
|
||||
"""
|
||||
|
||||
__json_schema_extra__ = {
|
||||
"country": {
|
||||
"multiple_items_allowed": True,
|
||||
"choices": sorted(COUNTRIES),
|
||||
},
|
||||
"calendar_id": {
|
||||
"multiple_items_allowed": True,
|
||||
},
|
||||
"importance": {
|
||||
"multiple_items_allowed": False,
|
||||
"choices": IMPORTANCE_CHOICES,
|
||||
},
|
||||
"group": {
|
||||
"multiple_items_allowed": False,
|
||||
"choices": GROUPS_CHOICES,
|
||||
},
|
||||
}
|
||||
country: str | None = Field(
|
||||
default=None,
|
||||
description="Country of the event.",
|
||||
)
|
||||
importance: IMPORTANCE | None = Field(
|
||||
default=None,
|
||||
description="Importance of the event.",
|
||||
)
|
||||
group: GROUPS | None = Field(
|
||||
default=None,
|
||||
description="Grouping of events.",
|
||||
)
|
||||
calendar_id: None | int | str = Field(
|
||||
default=None, description="Get events by TradingEconomics Calendar ID."
|
||||
)
|
||||
_number_of_countries: int = 0
|
||||
|
||||
@field_validator("country", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def validate_country(cls, c):
|
||||
"""Validate country."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from openbb_core.provider.utils.helpers import check_item
|
||||
|
||||
result: list = []
|
||||
values = c.replace(" ", "_").split(",")
|
||||
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", mode="after", check_fields=False)
|
||||
@classmethod
|
||||
def importance_to_number(cls, v):
|
||||
"""Convert importance to number."""
|
||||
string_to_value = {"low": 1, "medium": 2, "high": 3}
|
||||
return string_to_value.get(v.lower(), None) if v else None
|
||||
|
||||
|
||||
class TEEconomicCalendarData(EconomicCalendarData):
|
||||
"""Trading Economics Economic Calendar Data."""
|
||||
|
||||
__alias_dict__ = {
|
||||
"date": "Date",
|
||||
"country": "Country",
|
||||
"category": "Category",
|
||||
"event": "Event",
|
||||
"reference": "Reference",
|
||||
"reference_date": "ReferenceDate",
|
||||
"source": "Source",
|
||||
"source_url": "SourceURL",
|
||||
"actual": "Actual",
|
||||
"consensus": "Forecast",
|
||||
"forecast": "TEForecast",
|
||||
"te_url": "URL",
|
||||
"importance": "Importance",
|
||||
"currency": "Currency",
|
||||
"unit": "Unit",
|
||||
"ticker": "Ticker",
|
||||
"symbol": "Symbol",
|
||||
"previous": "Previous",
|
||||
"revised": "Revised",
|
||||
"last_updated": "LastUpdate",
|
||||
"calendar_id": "CalendarId",
|
||||
"date_span": "DateSpan",
|
||||
}
|
||||
forecast: str | float | None = Field(
|
||||
default=None, description="TradingEconomics projections."
|
||||
)
|
||||
reference: str | None = Field(
|
||||
default=None,
|
||||
description="Abbreviated period for which released data refers to.",
|
||||
)
|
||||
reference_date: dateType | None = Field(
|
||||
default=None, description="Date for the reference period."
|
||||
)
|
||||
calendar_id: int | None = Field(
|
||||
default=None, description="TradingEconomics Calendar ID."
|
||||
)
|
||||
date_span: int | None = Field(default=None, description="Date span of the event.")
|
||||
symbol: str | None = Field(default=None, description="TradingEconomics Symbol.")
|
||||
ticker: str | None = Field(
|
||||
default=None, description="TradingEconomics Ticker symbol."
|
||||
)
|
||||
te_url: str | None = Field(default=None, description="TradingEconomics URL path.")
|
||||
source_url: str | None = Field(default=None, description="Source URL.")
|
||||
last_updated: datetime | None = Field(
|
||||
default=None, description="Last update of the data."
|
||||
)
|
||||
|
||||
@field_validator("importance", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def importance_to_number(cls, v):
|
||||
"""Convert importance to number."""
|
||||
value_to_string = {1: "Low", 2: "Medium", 3: "High"}
|
||||
return value_to_string.get(v) if v else None
|
||||
|
||||
@field_validator("date", "last_updated", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def validate_datetime(cls, v: str) -> datetime:
|
||||
"""Validate the datetime values."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from pandas import to_datetime
|
||||
|
||||
dt = to_datetime(v, utc=True)
|
||||
return dt.replace(microsecond=0)
|
||||
|
||||
@field_validator("reference_date", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def validate_date(cls, v):
|
||||
"""Validate the date."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from pandas import to_datetime
|
||||
|
||||
return to_datetime(v, utc=True).date() if v else None
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def empty_strings(cls, values): # pylint: disable=no-self-argument
|
||||
"""Replace empty strings with None."""
|
||||
return (
|
||||
{
|
||||
k: None if isinstance(v, str) and v == "" else v
|
||||
for k, v in values.items()
|
||||
}
|
||||
if isinstance(values, dict)
|
||||
else values
|
||||
)
|
||||
|
||||
|
||||
class TEEconomicCalendarFetcher(
|
||||
Fetcher[
|
||||
TEEconomicCalendarQueryParams,
|
||||
list[TEEconomicCalendarData],
|
||||
]
|
||||
):
|
||||
"""Transform the query, extract and transform the data from the Trading Economics endpoints."""
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: dict[str, Any]) -> TEEconomicCalendarQueryParams:
|
||||
"""Transform the query params."""
|
||||
return TEEconomicCalendarQueryParams(**params)
|
||||
|
||||
@staticmethod
|
||||
async def aextract_data(
|
||||
query: TEEconomicCalendarQueryParams,
|
||||
credentials: dict[str, str] | None,
|
||||
**kwargs: Any,
|
||||
) -> dict | list[dict]:
|
||||
"""Return the raw data from the TE endpoint."""
|
||||
# pylint: disable=import-outside-toplevel
|
||||
from openbb_core.provider.utils.helpers import amake_request
|
||||
from openbb_tradingeconomics.utils import url_generator
|
||||
from openbb_tradingeconomics.utils.helpers import response_callback
|
||||
|
||||
api_key = credentials.get("tradingeconomics_api_key") if credentials else ""
|
||||
|
||||
if query.group is not None:
|
||||
query.group = query.group.replace("_", " ") # type: ignore
|
||||
|
||||
url = url_generator.generate_url(query)
|
||||
|
||||
if not url:
|
||||
raise OpenBBError(
|
||||
"No url generated. Check combination of input parameters."
|
||||
)
|
||||
|
||||
url = f"{url}{api_key}"
|
||||
|
||||
return await amake_request(url, response_callback=response_callback, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def transform_data(
|
||||
query: TEEconomicCalendarQueryParams, data: list[dict], **kwargs: Any
|
||||
) -> list[TEEconomicCalendarData]:
|
||||
"""Return the transformed data."""
|
||||
return [TEEconomicCalendarData.model_validate(d) for d in data]
|
||||
@@ -1,235 +0,0 @@
|
||||
"""Countries list for Trading Economics API."""
|
||||
|
||||
country_dict = {
|
||||
"G20": [
|
||||
"United States",
|
||||
"Euro Area",
|
||||
"China",
|
||||
"Japan",
|
||||
"Germany",
|
||||
"United Kingdom",
|
||||
"France",
|
||||
"India",
|
||||
"Italy",
|
||||
"Brazil",
|
||||
"Canada",
|
||||
"South Korea",
|
||||
"Russia",
|
||||
"Spain",
|
||||
],
|
||||
"Australia": [
|
||||
"Australia",
|
||||
"Fiji",
|
||||
"Kiribati",
|
||||
"New Caledonia",
|
||||
"New Zealand",
|
||||
"Papua New Guinea",
|
||||
"Samoa",
|
||||
"Solomon Islands",
|
||||
"Tonga",
|
||||
"Vanuatu",
|
||||
],
|
||||
"America": [
|
||||
"Antigua and Barbuda",
|
||||
"Argentina",
|
||||
"Aruba",
|
||||
"Bahamas",
|
||||
"Barbados",
|
||||
"Belize",
|
||||
"Bermuda",
|
||||
"Bolivia",
|
||||
"Brazil",
|
||||
"Canada",
|
||||
"Cayman Islands",
|
||||
"Chile",
|
||||
"Colombia",
|
||||
"Costa Rica",
|
||||
"Cuba",
|
||||
"Dominica",
|
||||
"Dominican Republic",
|
||||
"Ecuador",
|
||||
"El Salvador",
|
||||
"Grenada",
|
||||
"Guatemala",
|
||||
"Guyana",
|
||||
"Haiti",
|
||||
"Honduras",
|
||||
"Jamaica",
|
||||
"Mexico",
|
||||
"Nicaragua",
|
||||
"Panama",
|
||||
"Paraguay",
|
||||
"Peru",
|
||||
"Puerto Rico",
|
||||
"Suriname",
|
||||
"Trinidad and Tobago",
|
||||
"United States",
|
||||
"Uruguay",
|
||||
"Venezuela",
|
||||
],
|
||||
"Europe": [
|
||||
"Albania",
|
||||
"Andorra",
|
||||
"Austria",
|
||||
"Belarus",
|
||||
"Belgium",
|
||||
"Bosnia and Herzegovina",
|
||||
"Bulgaria",
|
||||
"Croatia",
|
||||
"Cyprus",
|
||||
"Czech Republic",
|
||||
"Denmark",
|
||||
"Estonia",
|
||||
"Euro area",
|
||||
"Faroe Islands",
|
||||
"Finland",
|
||||
"France",
|
||||
"Germany",
|
||||
"Greece",
|
||||
"Hungary",
|
||||
"Iceland",
|
||||
"Ireland",
|
||||
"Isle of Man",
|
||||
"Italy",
|
||||
"Kosovo",
|
||||
"Latvia",
|
||||
"Liechtenstein",
|
||||
"Lithuania",
|
||||
"Luxembourg",
|
||||
"Malta",
|
||||
"Moldova",
|
||||
"Monaco",
|
||||
"Montenegro",
|
||||
"Netherlands",
|
||||
"North Macedonia",
|
||||
"Norway",
|
||||
"Poland",
|
||||
"Portugal",
|
||||
"Romania",
|
||||
"Russia",
|
||||
"Serbia",
|
||||
"Slovakia",
|
||||
"Slovenia",
|
||||
"Spain",
|
||||
"Sweden",
|
||||
"Switzerland",
|
||||
"Turkey",
|
||||
"Ukraine",
|
||||
"United Kingdom",
|
||||
],
|
||||
"Africa": [
|
||||
"Algeria",
|
||||
"Angola",
|
||||
"Benin",
|
||||
"Botswana",
|
||||
"Burkina Faso",
|
||||
"Burundi",
|
||||
"Cameroon",
|
||||
"Cape Verde",
|
||||
"Central African Republic",
|
||||
"Chad",
|
||||
"Comoros",
|
||||
"Congo",
|
||||
"Djibouti",
|
||||
"Egypt",
|
||||
"Equatorial Guinea",
|
||||
"Eritrea",
|
||||
"Ethiopia",
|
||||
"Gabon",
|
||||
"Gambia",
|
||||
"Ghana",
|
||||
"Guinea",
|
||||
"Guinea Bissau",
|
||||
"Ivory Coast",
|
||||
"Kenya",
|
||||
"Lesotho",
|
||||
"Liberia",
|
||||
"Libya",
|
||||
"Madagascar",
|
||||
"Malawi",
|
||||
"Mali",
|
||||
"Mauritania",
|
||||
"Mauritius",
|
||||
"Morocco",
|
||||
"Mozambique",
|
||||
"Namibia",
|
||||
"Niger",
|
||||
"Nigeria",
|
||||
"Republic of the Congo",
|
||||
"Rwanda",
|
||||
"Sao Tome and Principe",
|
||||
"Senegal",
|
||||
"Seychelles",
|
||||
"Sierra Leone",
|
||||
"Somalia",
|
||||
"South Africa",
|
||||
"South Sudan",
|
||||
"Sudan",
|
||||
"Swaziland",
|
||||
"Tanzania",
|
||||
"Togo",
|
||||
"Tunisia",
|
||||
"Uganda",
|
||||
"Zambia",
|
||||
"Zimbabwe",
|
||||
],
|
||||
"Asia": [
|
||||
"Afghanistan",
|
||||
"Armenia",
|
||||
"Azerbaijan",
|
||||
"Bahrain",
|
||||
"Bangladesh",
|
||||
"Bhutan",
|
||||
"Brunei",
|
||||
"Cambodia",
|
||||
"China",
|
||||
"East Timor",
|
||||
"Georgia",
|
||||
"Hong Kong",
|
||||
"India",
|
||||
"Indonesia",
|
||||
"Iran",
|
||||
"Iraq",
|
||||
"Israel",
|
||||
"Japan",
|
||||
"Jordan",
|
||||
"Kazakhstan",
|
||||
"Kuwait",
|
||||
"Kyrgyzstan",
|
||||
"Laos",
|
||||
"Lebanon",
|
||||
"Macao",
|
||||
"Malaysia",
|
||||
"Maldives",
|
||||
"Mongolia",
|
||||
"Myanmar",
|
||||
"Nepal",
|
||||
"North Korea",
|
||||
"Oman",
|
||||
"Palestine",
|
||||
"Pakistan",
|
||||
"Philippines",
|
||||
"Qatar",
|
||||
"Saudi Arabia",
|
||||
"Singapore",
|
||||
"South Korea",
|
||||
"Sri Lanka",
|
||||
"Syria",
|
||||
"Taiwan",
|
||||
"Tajikistan",
|
||||
"Thailand",
|
||||
"Turkmenistan",
|
||||
"United Arab Emirates",
|
||||
"Uzbekistan",
|
||||
"Vietnam",
|
||||
"Yemen",
|
||||
],
|
||||
}
|
||||
|
||||
COUNTRIES = list(
|
||||
{
|
||||
item.lower().replace(" ", "_")
|
||||
for sublist in country_dict.values()
|
||||
for item in sublist
|
||||
}
|
||||
)
|
||||
@@ -1,24 +0,0 @@
|
||||
"""TradingEconomics Helpers."""
|
||||
|
||||
from openbb_core.app.model.abstract.error import OpenBBError
|
||||
from openbb_core.provider.utils.errors import EmptyDataError, UnauthorizedError
|
||||
|
||||
|
||||
async def response_callback(response, _) -> dict | list[dict]:
|
||||
"""Return the response."""
|
||||
if response.status != 200:
|
||||
message = await response.text()
|
||||
|
||||
if "credentials" in message or "unauthorized" in message.lower():
|
||||
raise UnauthorizedError(
|
||||
f"Unauthorized TradingEconomics request -> {message}"
|
||||
)
|
||||
|
||||
raise OpenBBError(f"{response.status} -> {message}")
|
||||
|
||||
results = await response.json()
|
||||
|
||||
if not results:
|
||||
raise EmptyDataError("The request was returned empty.")
|
||||
|
||||
return results
|
||||
@@ -1,96 +0,0 @@
|
||||
"""Helper to generate urls for Trading Economics API."""
|
||||
|
||||
from datetime import date
|
||||
from urllib.parse import quote, urlencode
|
||||
|
||||
|
||||
def check_args(query_args: dict, to_include: list[str]):
|
||||
"""Check if all fields in to_include are present in query_args."""
|
||||
available_args = ["country", "start_date", "end_date", "importance", "group"]
|
||||
|
||||
# Check if all fields in to_include are present in query_args
|
||||
# and elements in available_args that are not in to_include are not present in query_args
|
||||
return all(field in query_args for field in to_include) and all(
|
||||
field not in query_args for field in available_args if field not in to_include
|
||||
)
|
||||
|
||||
|
||||
# pylint: disable = R0912
|
||||
def generate_url(in_query):
|
||||
"""Generate the url for trading economimcs.
|
||||
|
||||
There is not a single api endpoint to hit so these are generated based on the combinations.
|
||||
There are also some combinations that return no data so that will return an empty string.
|
||||
"""
|
||||
# Converting the input query to a dict of params that are not None
|
||||
query = {k: v for k, v in in_query.dict().items() if v is not None}
|
||||
|
||||
# Nothing -- just a snapshot
|
||||
if not query:
|
||||
return "https://api.tradingeconomics.com/calendar?c="
|
||||
|
||||
# Both start and end date are required
|
||||
if "start_date" in query and "end_date" not in query:
|
||||
query["end_date"] = date.today().strftime("%Y-%m-%d")
|
||||
if "end_date" in query and "start_date" not in query:
|
||||
query["start_date"] = query["end_date"]
|
||||
|
||||
# Handle the formatting for the api
|
||||
if "country" in query:
|
||||
country = quote(query["country"].replace("_", " "))
|
||||
if "group" in query:
|
||||
group = quote(query["group"])
|
||||
|
||||
base_url = "https://api.tradingeconomics.com/calendar"
|
||||
url = ""
|
||||
|
||||
# Construct URL based on query parameters
|
||||
# Country Only
|
||||
if check_args(query, ["country"]):
|
||||
# pylint: disable=possibly-used-before-assignment
|
||||
url = f"{base_url}/country/{country}?c="
|
||||
# Country + Date
|
||||
elif check_args(query, ["country", "start_date", "end_date"]):
|
||||
url = (
|
||||
f"{base_url}/country/{country}/{query['start_date']}/{query['end_date']}?c="
|
||||
)
|
||||
# Country + Importance
|
||||
elif check_args(query, ["country", "importance"]):
|
||||
url = f"{base_url}/country/{country}?{urlencode(query)}&c="
|
||||
# Country + Group
|
||||
elif check_args(query, ["country", "group"]):
|
||||
# pylint: disable=possibly-used-before-assignment
|
||||
url = f"{base_url}/country/{country}/group/{group}?c="
|
||||
# Country + Group + Date
|
||||
elif check_args(query, ["country", "group", "start_date", "end_date"]):
|
||||
url = f"{base_url}/country/{country}/group/{group}/{query['start_date']}/{query['end_date']}?c="
|
||||
# Country + Date + Importance
|
||||
elif check_args(query, ["country", "importance", "start_date", "end_date"]):
|
||||
url = f"{base_url}/country/{country}/{query['start_date']}/{query['end_date']}?{urlencode(query)}&c="
|
||||
# By date only
|
||||
elif check_args(query, ["start_date", "end_date"]):
|
||||
url = f"{base_url}/country/All/{query['start_date']}/{query['end_date']}?c="
|
||||
# By importance only
|
||||
elif check_args(query, ["importance"]):
|
||||
url = f"{base_url}?{urlencode(query)}&c="
|
||||
# By importance and date
|
||||
elif check_args(query, ["importance", "start_date", "end_date"]):
|
||||
url = f"{base_url}/country/All/{query['start_date']}/{query['end_date']}?{urlencode(query)}&c="
|
||||
# Group Only
|
||||
elif check_args(query, ["group"]):
|
||||
url = f"{base_url}/group/{query['group']}?c="
|
||||
# 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="
|
||||
# Calendar IDs
|
||||
elif check_args(query, ["calendar_id"]):
|
||||
url = f"{base_url}/calendarid/{str(query['calendar_id'])}?c="
|
||||
|
||||
return url if url else ""
|
||||
1959
openbb_platform/providers/tradingeconomics/poetry.lock
generated
vendored
1959
openbb_platform/providers/tradingeconomics/poetry.lock
generated
vendored
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
||||
[tool.poetry]
|
||||
name = "openbb-tradingeconomics"
|
||||
version = "1.6.1"
|
||||
description = "Trading Economics extension for OpenBB"
|
||||
authors = ["OpenBB Team <hello@openbb.co>"]
|
||||
license = "AGPL-3.0-only"
|
||||
readme = "README.md"
|
||||
packages = [{ include = "openbb_tradingeconomics" }]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.10,<4"
|
||||
openbb-core = "^1.6.10"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[tool.poetry.plugins."openbb_provider_extension"]
|
||||
tradingeconomics = "openbb_tradingeconomics:tradingeconomics_provider"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,35 +0,0 @@
|
||||
"""Test the Trading Economics fetchers."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
from openbb_core.app.service.user_service import UserService
|
||||
from openbb_tradingeconomics.models.economic_calendar import TEEconomicCalendarFetcher
|
||||
|
||||
test_credentials = UserService().default_user_settings.credentials.model_dump(
|
||||
mode="json"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vcr_config():
|
||||
"""VCR configuration."""
|
||||
return {
|
||||
"filter_headers": [("User-Agent", None)],
|
||||
"filter_query_parameters": [
|
||||
("c", "mock_api_key"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.record_http
|
||||
def test_tradingeconomics_economic_calendar_fetcher(credentials=test_credentials):
|
||||
"""Test the Trading Economics economic calendar fetcher."""
|
||||
params = {
|
||||
"start_date": date(2023, 1, 1),
|
||||
"end_date": date(2023, 6, 6),
|
||||
}
|
||||
|
||||
fetcher = TEEconomicCalendarFetcher()
|
||||
result = fetcher.test(params, credentials)
|
||||
assert result is None
|
||||
@@ -1,82 +0,0 @@
|
||||
"""Test the url generator."""
|
||||
|
||||
from unittest.mock import Mock
|
||||
|
||||
from providers.tradingeconomics.openbb_tradingeconomics.utils.url_generator import (
|
||||
check_args,
|
||||
generate_url,
|
||||
)
|
||||
|
||||
|
||||
def test_check_args_valid():
|
||||
"""Test check_args with valid args."""
|
||||
query_args = {"country": "US", "start_date": "2023-01-01", "end_date": "2023-01-31"}
|
||||
to_include = ["country", "start_date", "end_date"]
|
||||
assert check_args(query_args, to_include)
|
||||
|
||||
|
||||
def test_check_args_invalid():
|
||||
"""Test check_args with missing args."""
|
||||
query_args = {"country": "US"}
|
||||
to_include = ["start_date", "end_date"]
|
||||
assert not check_args(query_args, to_include)
|
||||
|
||||
|
||||
def create_query_mock(query_dict):
|
||||
"""Create a query mock."""
|
||||
query_mock = Mock()
|
||||
query_mock.dict.return_value = query_dict
|
||||
return query_mock
|
||||
|
||||
|
||||
def test_generate_url_country_only():
|
||||
"""Test generate_url with country."""
|
||||
query_mock = create_query_mock({"country": "US"})
|
||||
expected_url = "https://api.tradingeconomics.com/calendar/country/US?c="
|
||||
assert generate_url(query_mock) == expected_url
|
||||
|
||||
|
||||
def test_generate_url_country_and_dates():
|
||||
"""Test generate_url with country and dates."""
|
||||
query_mock = create_query_mock(
|
||||
{"country": "US", "start_date": "2023-01-01", "end_date": "2023-01-31"}
|
||||
)
|
||||
expected_url = (
|
||||
"https://api.tradingeconomics.com/calendar/country/US/2023-01-01/2023-01-31?c="
|
||||
)
|
||||
assert generate_url(query_mock) == expected_url
|
||||
|
||||
|
||||
def test_generate_url_importance_only():
|
||||
"""Test generate_url with importance."""
|
||||
query_mock = create_query_mock({"importance": "High"})
|
||||
expected_url = "https://api.tradingeconomics.com/calendar?importance=High&c="
|
||||
assert generate_url(query_mock) == expected_url
|
||||
|
||||
|
||||
def test_generate_url_no_data():
|
||||
"""Test generate_url with no data."""
|
||||
query_mock = create_query_mock({})
|
||||
expected_url = "https://api.tradingeconomics.com/calendar?c="
|
||||
assert generate_url(query_mock) == expected_url
|
||||
|
||||
|
||||
def test_generate_url_group_only():
|
||||
"""Test generate_url with group."""
|
||||
query_mock = create_query_mock({"group": "G20"})
|
||||
expected_url = "https://api.tradingeconomics.com/calendar/group/G20?c="
|
||||
assert generate_url(query_mock) == expected_url
|
||||
|
||||
|
||||
def test_generate_url_country_group_and_dates():
|
||||
"""Test generate_url with country, group, and dates."""
|
||||
query_mock = create_query_mock(
|
||||
{
|
||||
"country": "US",
|
||||
"group": "G20",
|
||||
"start_date": "2023-01-01",
|
||||
"end_date": "2023-01-31",
|
||||
}
|
||||
)
|
||||
expected_url = "https://api.tradingeconomics.com/calendar/country/US/group/G20/2023-01-01/2023-01-31?c="
|
||||
assert generate_url(query_mock) == expected_url
|
||||
Reference in New Issue
Block a user