summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/balance_of_payments.py79
-rw-r--r--openbb_platform/extensions/economy/integration/test_economy_api.py8
-rw-r--r--openbb_platform/extensions/economy/integration/test_economy_python.py8
-rw-r--r--openbb_platform/extensions/economy/openbb_economy/economy_router.py2
-rw-r--r--openbb_platform/openbb/assets/reference.json248
-rw-r--r--openbb_platform/openbb/package/economy.py109
-rw-r--r--openbb_platform/providers/fred/openbb_fred/__init__.py2
-rw-r--r--openbb_platform/providers/fred/openbb_fred/models/balance_of_payments.py122
-rw-r--r--openbb_platform/providers/fred/openbb_fred/utils/fred_helpers.py134
-rw-r--r--openbb_platform/providers/fred/tests/record/http/test_fred_fetchers/test_fred_balance_of_payments_fetcher.yaml1810
-rw-r--r--openbb_platform/providers/fred/tests/test_fred_fetchers.py15
11 files changed, 2536 insertions, 1 deletions
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/balance_of_payments.py b/openbb_platform/core/openbb_core/provider/standard_models/balance_of_payments.py
index 1cd73fc14d8..d2919801714 100644
--- a/openbb_platform/core/openbb_core/provider/standard_models/balance_of_payments.py
+++ b/openbb_platform/core/openbb_core/provider/standard_models/balance_of_payments.py
@@ -15,6 +15,85 @@ class BalanceOfPaymentsQueryParams(QueryParams):
"""Balance Of Payments Query."""
+class BP6BopUsdData(Data):
+ """OECD BP6 Balance of Payments Items, in USD."""
+
+ period: dateType = Field(
+ default=None,
+ description="The date representing the beginning of the reporting period.",
+ )
+ balance_percent_of_gdp: Optional[float] = Field(
+ default=None,
+ description="Current Account Balance as Percent of GDP",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ balance_total: Optional[float] = Field(
+ default=None, description="Current Account Total Balance (USD)"
+ )
+ balance_total_services: Optional[float] = Field(
+ default=None, description="Current Account Total Services Balance (USD)"
+ )
+ balance_total_secondary_income: Optional[float] = Field(
+ default=None, description="Current Account Total Secondary Income Balance (USD)"
+ )
+ balance_total_goods: Optional[float] = Field(
+ default=None, description="Current Account Total Goods Balance (USD)"
+ )
+ balance_total_primary_income: Optional[float] = Field(
+ default=None, description="Current Account Total Primary Income Balance (USD)"
+ )
+ credits_services_percent_of_goods_and_services: Optional[float] = Field(
+ default=None,
+ description="Current Account Credits Services as Percent of Goods and Services",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ credits_services_percent_of_current_account: Optional[float] = Field(
+ default=None,
+ description="Current Account Credits Services as Percent of Current Account",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ credits_total_services: Optional[float] = Field(
+ default=None, description="Current Account Credits Total Services (USD)"
+ )
+ credits_total_goods: Optional[float] = Field(
+ default=None, description="Current Account Credits Total Goods (USD)"
+ )
+ credits_total_primary_income: Optional[float] = Field(
+ default=None, description="Current Account Credits Total Primary Income (USD)"
+ )
+ credits_total_secondary_income: Optional[float] = Field(
+ default=None, description="Current Account Credits Total Secondary Income (USD)"
+ )
+ credits_total: Optional[float] = Field(
+ default=None, description="Current Account Credits Total (USD)"
+ )
+ debits_services_percent_of_goods_and_services: Optional[float] = Field(
+ default=None,
+ description="Current Account Debits Services as Percent of Goods and Services",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ debits_services_percent_of_current_account: Optional[float] = Field(
+ default=None,
+ description="Current Account Debits Services as Percent of Current Account",
+ json_schema_extra={"x-unit_measurement": "percent", "x-frontend_multiply": 100},
+ )
+ debits_total_services: Optional[float] = Field(
+ default=None, description="Current Account Debits Total Services (USD)"
+ )
+ debits_total_goods: Optional[float] = Field(
+ default=None, description="Current Account Debits Total Goods (USD)"
+ )
+ debits_total_primary_income: Optional[float] = Field(
+ default=None, description="Current Account Debits Total Primary Income (USD)"
+ )
+ debits_total: Optional[float] = Field(
+ default=None, description="Current Account Debits Total (USD)"
+ )
+ debits_total_secondary_income: Optional[float] = Field(
+ default=None, description="Current Account Debits Total Secondary Income (USD)"
+ )
+
+
class ECBMain(Data):
"""ECB Main Balance of Payments Items."""
diff --git a/openbb_platform/extensions/economy/integration/test_economy_api.py b/openbb_platform/extensions/economy/integration/test_economy_api.py
index f8de0ee5ca1..3f7998c14de 100644
--- a/openbb_platform/extensions/economy/integration/test_economy_api.py
+++ b/openbb_platform/extensions/economy/integration/test_economy_api.py
@@ -251,6 +251,14 @@ def test_economy_gdp_real(params, headers):
"provider": "ecb",
}
),
+ (
+ {
+ "country": "united_states",
+ "start_date": None,
+ "end_date": None,
+ "provider": "fred",
+ }
+ ),
],
)
@pytest.mark.integration
diff --git a/openbb_platform/extensions/economy/integration/test_economy_python.py b/openbb_platform/extensions/economy/integration/test_economy_python.py
index dec33dacb6e..75a01123c7b 100644
--- a/openbb_platform/extensions/economy/integration/test_economy_python.py
+++ b/openbb_platform/extensions/economy/integration/test_economy_python.py
@@ -212,6 +212,14 @@ def test_economy_gdp_real(params, obb):
"provider": "ecb",
}
),
+ (
+ {
+ "country": "united_states",
+ "start_date": None,
+ "end_date": None,
+ "provider": "fred",
+ }
+ ),
],
)
@pytest.mark.integration
diff --git a/openbb_platform/extensions/economy/openbb_economy/economy_router.py b/openbb_platform/extensions/economy/openbb_economy/economy_router.py
index 19eb403cea1..6adeaeea1ea 100644
--- a/openbb_platform/extensions/economy/openbb_economy/economy_router.py
+++ b/openbb_platform/extensions/economy/openbb_economy/economy_router.py
@@ -93,6 +93,8 @@ async def risk_premium(
@router.command(
model="BalanceOfPayments",
examples=[
+ APIEx(parameters={"provider": "fred"}),
+ APIEx(parameters={"provider": "fred", "country": "brazil"}),
APIEx(parameters={"provider": "ecb"}),
APIEx(parameters={"report_type": "summary", "provider": "ecb"}),
APIEx(
diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json
index d668796f81c..ff6e4f6f446 100644
--- a/openbb_platform/openbb/assets/reference.json
+++ b/openbb_platform/openbb/assets/reference.json
@@ -3153,6 +3153,254 @@
},
"model": "RiskPremium"
},
+ "/economy/balance_of_payments": {
+ "deprecated": {
+ "flag": null,
+ "message": null
+ },
+ "description": "Balance of Payments Reports.",
+ "examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.balance_of_payments(provider='fred')\nobb.economy.balance_of_payments(provider='fred', country=brazil)\n```\n\n",
+ "parameters": {
+ "standard": [
+ {
+ "name": "provider",
+ "type": "Literal['fred']",
+ "description": "The provider to use for the query, by default None. If None, the provider specified in defaults is selected or 'fred' if there is no default.",
+ "default": "fred",
+ "optional": true
+ }
+ ],
+ "fred": [
+ {
+ "name": "country",
+ "type": "Literal['argentina', 'australia', 'austria', 'belgium', 'brazil', 'canada', 'chile', 'china', 'colombia', 'costa_rica', 'czechia', 'denmark', 'estonia', 'finland', 'france', 'germany', 'greece', 'hungary', 'iceland', 'india', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'korea', 'latvia', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'norway', 'poland', 'portugal', 'russia', 'saudi_arabia', 'slovak_republic', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'turkey', 'united_kingdom', 'united_states', 'g7', 'g20']",
+ "description": "The country to get data. Enter as a 3-letter ISO country code, default is USA.",
+ "default": "united_states",
+ "optional": true,
+ "choices": "argentina,australia,austria,belgium,brazil,canada,chile,china,colombia,costa_rica,czechia,denmark,estonia,finland,france,germany,greece,hungary,iceland,india,indonesia,ireland,israel,italy,japan,korea,latvia,lithuania,luxembourg,mexico,netherlands,new_zealand,norway,poland,portugal,russia,saudi_arabia,slovak_republic,slovenia,south_africa,spain,sweden,switzerland,turkey,united_kingdom,united_states,g7,g20"
+ },
+ {
+ "name": "start_date",
+ "type": "Union[date, str]",
+ "description": "Start date of the data, in YYYY-MM-DD format.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "end_date",
+ "type": "Union[date, str]",
+ "description": "End date of the data, in YYYY-MM-DD format.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ }
+ ]
+ },
+ "returns": {
+ "OBBject": [
+ {
+ "name": "results",
+ "type": "List[BalanceOfPayments]",
+ "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": "period",
+ "type": "date",
+ "description": "The date representing the beginning of the reporting period.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "balance_percent_of_gdp",
+ "type": "float",
+ "description": "Current Account Balance as Percent of GDP",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "balance_total",
+ "type": "float",
+ "description": "Current Account Total Balance (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "balance_total_services",
+ "type": "float",
+ "description": "Current Account Total Services Balance (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "balance_total_secondary_income",
+ "type": "float",
+ "description": "Current Account Total Secondary Income Balance (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "balance_total_goods",
+ "type": "float",
+ "description": "Current Account Total Goods Balance (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "balance_total_primary_income",
+ "type": "float",
+ "description": "Current Account Total Primary Income Balance (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_services_percent_of_goods_and_services",
+ "type": "float",
+ "description": "Current Account Credits Services as Percent of Goods and Services",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_services_percent_of_current_account",
+ "type": "float",
+ "description": "Current Account Credits Services as Percent of Current Account",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_total_services",
+ "type": "float",
+ "description": "Current Account Credits Total Services (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_total_goods",
+ "type": "float",
+ "description": "Current Account Credits Total Goods (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_total_primary_income",
+ "type": "float",
+ "description": "Current Account Credits Total Primary Income (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_total_secondary_income",
+ "type": "float",
+ "description": "Current Account Credits Total Secondary Income (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "credits_total",
+ "type": "float",
+ "description": "Current Account Credits Total (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_services_percent_of_goods_and_services",
+ "type": "float",
+ "description": "Current Account Debits Services as Percent of Goods and Services",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_services_percent_of_current_account",
+ "type": "float",
+ "description": "Current Account Debits Services as Percent of Current Account",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_total_services",
+ "type": "float",
+ "description": "Current Account Debits Total Services (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_total_goods",
+ "type": "float",
+ "description": "Current Account Debits Total Goods (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_total_primary_income",
+ "type": "float",
+ "description": "Current Account Debits Total Primary Income (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_total",
+ "type": "float",
+ "description": "Current Account Debits Total (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "debits_total_secondary_income",
+ "type": "float",
+ "description": "Current Account Debits Total Secondary Income (USD)",
+ "default": null,
+ "optional": true,
+ "choices": null
+ }
+ ],
+ "fred": []
+ },
+ "model": "BalanceOfPayments"
+ },
"/economy/fred_search": {
"deprecated": {
"flag": null,
diff --git a/openbb_platform/openbb/package/economy.py b/openbb_platform/openbb/package/economy.py
index fcf6f22d4c8..0a589831355 100644
--- a/openbb_platform/openbb/package/economy.py
+++ b/openbb_platform/openbb/package/economy.py
@@ -14,6 +14,7 @@ from typing_extensions import Annotated
class ROUTER_economy(Container):
"""/economy
available_indicators
+ balance_of_payments
calendar
composite_leading_indicator
country_profile
@@ -124,6 +125,114 @@ class ROUTER_economy(Container):
@exception_handler
@validate
+ def balance_of_payments(
+ self,
+ provider: Annotated[
+ Optional[Literal["fred"]],
+ OpenBBField(
+ description="The provider to use for the query, by default None.\n If None, the provider specified in defaults is selected or 'fred' if there is\n no default."
+ ),
+ ] = None,
+ **kwargs
+ ) -> OBBject:
+ """Balance of Payments Reports.
+
+ Parameters
+ ----------
+ provider : Optional[Literal['fred']]
+ The provider to use for the query, by default None.
+ If None, the provider specified in defaults is selected or 'fred' if there is
+ no default.
+ country : Literal['argentina', 'australia', 'austria', 'belgium', 'brazil', 'canada', 'chile', 'china', 'colombia', 'costa_rica', 'czechia', 'denmark', 'estonia', 'finland', 'france', 'germany', 'greece', 'hungary', 'iceland', 'india', 'indonesia', 'ireland', 'israel', 'italy', 'japan', 'korea', 'latvia', 'lithuania', 'luxembourg', 'mexico', 'netherlands', 'new_zealand', 'norway', 'poland', 'portugal', 'russia', 'saudi_arabia', 'slovak_republic', 'slovenia', 'south_africa', 'spain', 'sweden', 'switzerland', 'turkey', 'united_kingdom', 'united_states', 'g7', 'g20']
+ The country to get data. Enter as a 3-letter ISO country code, default is USA. (provider: fred)
+ start_date : Optional[datetime.date]
+ Start date of the data, in YYYY-MM-DD format. (provider: fred)
+ end_date : Optional[datetime.date]
+ End date of the data, in YYYY-MM-DD format. (provider: fred)
+
+ Returns
+ -------
+ OBBject
+ results : List[BalanceOfPayments]
+ Serializable results.
+ provider : Optional[Literal['fred']]
+ Provider name.
+ warnings : Optional[List[Warning_]]
+ List of warnings.
+ chart : Optional[Chart]
+ Chart object.
+ extra : Dict[str, Any]
+ Extra info.
+
+ BalanceOfPayments
+ -----------------
+ period : Optional[date]
+ The date representing the beginning of the reporting period.
+ balance_percent_of_gdp : Optional[float]
+ Current Account Balance as Percent of GDP
+ balance_total : Optional[float]
+ Current Account Total Balance (USD)
+ balance_total_services : Optional[float]
+ Current Account Total Services Balance (USD)
+ balance_total_secondary_income : Optional[float]
+ Current Account Total Secondary Income Balance (USD)
+ balance_total_goods : Optional[float]
+ Current Account Total Goods Balance (USD)
+ balance_total_primary_income : Optional[float]
+ Current Account Total Primary Income Balance (USD)
+ credits_services_percent_of_goods_and_services : Optional[float]
+ Current Account Credits Services as Percent of Goods and Services
+ credits_services_percent_of_current_account : Optional[float]
+ Current Account Credits Services as Percent of Current Account
+ credits_total_services : Optional[float]
+ Current Account Credits Total Services (USD)
+ credits_total_goods : Optional[float]
+ Current Account Credits Total Goods (USD)
+ credits_total_primary_income : Optional[float]
+ Current Account Credits Total Primary Income (USD)
+ credits_total_secondary_income : Optional[float]
+ Current Account Credits Total Secondary Income (USD)
+ credits_total : Optional[float]
+ Current Account Credits Total (USD)
+ debits_services_percent_of_goods_and_services : Optional[float]
+ Current Account Debits Services as Percent of Goods and Services
+ debits_services_percent_of_current_account : Optional[float]
+ Current Account Debits Services as Percent of Current Account
+ debits_total_services : Optional[float]
+ Current Account Debits Total Services (USD)
+ debits_total_goods : Optional[float]
+ Current Account Debits Total Goods (USD)
+ debits_total_primary_income : Optional[float]
+ Current Account Debits Total Primary Income (USD)
+ debits_total : Optional[float]
+ Current Account Debits Total (USD)
+ debits_total_secondary_income : Optional[float]
+ Current Account Debits Total Secondary Income (USD)
+
+ Examples
+ --------
+ >>> from openbb import obb
+ >>> obb.economy.balance_of_payments(provider='fred')
+ >>> obb.economy.balance_of_payments(provider='fred', country='brazil')
+ """ # noqa: E501
+
+ return self._run(
+ "/economy/balance_of_payments",
+ **filter_inputs(
+ provider_choices={
+ "provider": self._get_provider(
+ provider,
+ "/economy/balance_of_payments",
+ ("fred",),
+ )
+ },
+ standard_params={},
+ extra_params=kwargs,
+ )
+ )
+
+ @exception_handler
+ @validate
def calendar(
self,
start_date: Annotated[
diff --git a/openbb_platform/providers/fred/openbb_fred/__init__.py b/openbb_platform/providers/fred/openbb_fred/__init__.py
index b6efbd173a6..8e4b6dbceb5 100644
--- a/openbb_platform/providers/fred/openbb_fred/__init__.py
+++ b/openbb_platform/providers/fred/openbb_fred/__init__.py
@@ -2,6 +2,7 @@
from openbb_core.provider.abstract.provider import Provider
from openbb_fred.models.ameribor_rates import FREDAMERIBORFetcher
+from openbb_fred.models.balance_of_payments import FredBalanceOfPaymentsFetcher
from openbb_fred.models.cp import FREDCommercialPaperFetcher
from openbb_fred.models.cpi import FREDConsumerPriceIndexFetcher
from openbb_fred.models.dwpcr_rates import FREDDiscountWindowPrimaryCreditRateFetcher
@@ -36,6 +37,7 @@ Research division of the Federal Reserve Bank of St. Louis that has more than
816,000 economic time series from various sources.""",
credentials=["api_key"],
fetcher_dict={
+ "BalanceOfPayments": FredBalanceOfPaymentsFetcher,
"ConsumerPriceIndex": FREDConsumerPriceIndexFetcher,
"USYieldCurve": FREDYieldCurveFetcher,
"SOFR": FREDSOFRFetcher,
diff --git a/openbb_platform/providers/fred/openbb_fred/models/balance_of_payments.py b/openbb_platform/providers/fred/openbb_fred/models/balance_of_payments.py
new file mode 100644
index 00000000000..bfb2e7481a8
--- /dev/null
+++ b/openbb_platform/providers/fred/openbb_fred/models/balance_of_payments.py
@@ -0,0 +1,122 @@
+"""FRED Balance Of Payments Model."""
+
+# pylint: disable=unused-argument
+
+from datetime import date as dateType
+from typing import Any, Dict, List, Optional
+
+from openbb_core.provider.abstract.annotated_result import AnnotatedResult
+from openbb_core.provider.abstract.fetcher import Fetcher
+from openbb_core.provider.standard_models.balance_of_payments import (
+ BalanceOfPaymentsQueryParams,
+ BP6BopUsdData,
+)
+from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS
+from openbb_core.provider.utils.errors import EmptyDataError
+from openbb_fred.models.series import (
+ FredSeriesFetcher,
+ FredSeriesQueryParams,
+)
+from openbb_fred.utils.fred_helpers import (
+ BOP_COUNTRIES,
+ BOP_COUNTRY_CHOICES,
+ get_bop_series,
+)
+from pandas import DataFrame
+from pydantic import Field, field_validator
+
+
+class FredBalanceOfPaymentsQueryParams(BalanceOfPaymentsQueryParams):
+ """FRED Balance Of Payments Query Parameters."""
+
+ country: BOP_COUNTRY_CHOICES = Field(
+ default="united_states",
+ description=QUERY_DESCRIPTIONS.get("country", "")
+ + " Enter as a 3-letter ISO country code, default is USA.",
+ json_schema_extra={"choices": ",".join(list(BOP_COUNTRIES))},
+ )
+ start_date: Optional[dateType] = Field(
+ default=None,
+ description=QUERY_DESCRIPTIONS.get("start_date", ""),
+ )
+ end_date: Optional[dateType] = Field(
+ default=None,
+ description=QUERY_DESCRIPTIONS.get("end_date", ""),
+ )
+
+
+class FredBalanceOfPaymentsData(BP6BopUsdData):
+ """FRED Balance Of Payments Data."""
+
+ __alias_dict__ = {"period": "date"}
+
+ @field_validator(
+ "balance_percent_of_gdp",
+ "credits_services_percent_of_goods_and_services",
+ "credits_services_percent_of_current_account",
+ "debits_services_percent_of_goods_and_services",
+ "debits_services_percent_of_current_account",
+ mode="before",
+ check_fields=False,
+ )
+ @classmethod
+ def normalize_percent(cls, v):