Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Consolidate OECD Interest Rate Endpoints as a Single Function #6602

Merged
merged 11 commits into from
Aug 2, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Country Interest Rates Standard Model."""

from datetime import date as dateType
from typing import Optional

from pydantic import Field

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.descriptions import (
DATA_DESCRIPTIONS,
QUERY_DESCRIPTIONS,
)


class CountryInterestRatesQueryParams(QueryParams):
"""Country Interest Rates Query."""

country: str = Field(
default="united_states",
description=QUERY_DESCRIPTIONS.get("country"),
)
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 CountryInterestRatesData(Data):
"""Country Interest Rates Data."""

date: dateType = Field(default=None, description=DATA_DESCRIPTIONS.get("date"))
value: float = Field(
default=None,
description="The interest rate value.",
json_schema_extra={"x-unit_measurment": "percent", "x-frontend_multiply": 100},
)
country: Optional[str] = Field(
default=None,
description="Country for which the interest rate is given.",
)
27 changes: 27 additions & 0 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,33 @@ def test_economy_immediate_interest_rate(params, headers):
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"country": "united_states",
"frequency": "monthly",
"provider": "oecd",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"duration": "long",
}
),
],
)
@pytest.mark.integration
def test_economy_interest_rates(params, headers):
"""Test the economy interest rates endpoint."""
params = {p: v for p, v in params.items() if v}

query_str = get_querystring(params, [])
url = f"http://0.0.0.0:8000/api/v1/economy/interest_rates?{query_str}"
result = requests.get(url, headers=headers, timeout=30)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,32 @@ def test_economy_immediate_interest_rate(params, obb):
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"country": "united_states",
"frequency": "monthly",
"provider": "oecd",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"duration": "long",
}
),
],
)
@pytest.mark.integration
def test_economy_interest_rates(params, obb):
"""Test economy country interest rates endpoint."""
params = {p: v for p, v in params.items() if v}

result = obb.economy.interest_rates(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Economy Router."""

from openbb_core.app.deprecation import OpenBBDeprecationWarning
from openbb_core.app.model.command_context import CommandContext
from openbb_core.app.model.example import APIEx
from openbb_core.app.model.obbject import OBBject
Expand Down Expand Up @@ -255,6 +256,12 @@ async def composite_leading_indicator(

@router.command(
model="STIR",
deprecated=True,
deprecation=OpenBBDeprecationWarning(
message="This endpoint will be removed in a future version. Use, `/economy/interest_rates`, instead.",
since=(4, 3),
expected_removal=(4, 5),
),
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(
Expand Down Expand Up @@ -282,6 +289,12 @@ async def short_term_interest_rate(

@router.command(
model="LTIR",
deprecated=True,
deprecation=OpenBBDeprecationWarning(
message="This endpoint will be removed in a future version. Use, `/economy/interest_rates`, instead.",
since=(4, 3),
expected_removal=(4, 5),
),
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(
Expand Down Expand Up @@ -492,6 +505,12 @@ async def house_price_index(

@router.command(
model="ImmediateInterestRate",
deprecated=True,
deprecation=OpenBBDeprecationWarning(
message="This endpoint will be removed in a future version. Use, `/economy/interest_rates`, instead.",
since=(4, 3),
expected_removal=(4, 5),
),
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(
Expand All @@ -514,6 +533,44 @@ async def immediate_interest_rate(
return await OBBject.from_query(Query(**locals()))


@router.command(
model="CountryInterestRates",
examples=[
APIEx(parameters={"provider": "oecd"}),
APIEx(
description="For OECD, duration can be 'immediate', 'short', or 'long'."
+ " Default is 'short', which is the 3-month rate."
+ " Overnight interbank rate is 'immediate', and 10-year rate is 'long'.",
parameters={
"provider": "oecd",
"country": "all",
"duration": "immediate",
"frequency": "quarter",
},
),
APIEx(
description="Multiple countries can be passed in as a list.",
parameters={
"duration": "long",
"country": "united_kingdom,germany",
"frequency": "monthly",
"provider": "oecd",
},
),
],
)
async def interest_rates(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject:
"""Get interest rates by country(s) and duration.
Most OECD countries publish short-term, a long-term, and immediate rates monthly.
"""
return await OBBject.from_query(Query(**locals()))


@router.command(
model="RetailPrices",
examples=[
Expand Down
136 changes: 128 additions & 8 deletions openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -6388,8 +6388,8 @@
},
"/economy/short_term_interest_rate": {
"deprecated": {
"flag": null,
"message": null
"flag": true,
"message": "This endpoint will be removed in a future version. Use, `/economy/interest_rates`, instead. Deprecated in OpenBB Platform V4.3 to be removed in V4.5."
},
"description": "Get Short-term interest rates.\n\nThey are the rates at which short-term borrowings are effected between\nfinancial institutions or the rate at which short-term government paper is issued or traded in the market.\n\nShort-term interest rates are generally averages of daily rates, measured as a percentage.\nShort-term interest rates are based on three-month money market rates where available.\nTypical standardised names are \"money market rate\" and \"treasury bill rate\".",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.short_term_interest_rate(provider='oecd')\nobb.economy.short_term_interest_rate(country=all, frequency=quarterly, provider='oecd')\n```\n\n",
Expand Down Expand Up @@ -6500,8 +6500,8 @@
},
"/economy/long_term_interest_rate": {
"deprecated": {
"flag": null,
"message": null
"flag": true,
"message": "This endpoint will be removed in a future version. Use, `/economy/interest_rates`, instead. Deprecated in OpenBB Platform V4.3 to be removed in V4.5."
},
"description": "Get Long-term interest rates that refer to government bonds maturing in ten years.\n\nRates are mainly determined by the price charged by the lender, the risk from the borrower and the\nfall in the capital value. Long-term interest rates are generally averages of daily rates,\nmeasured as a percentage. These interest rates are implied by the prices at which the government bonds are\ntraded on financial markets, not the interest rates at which the loans were issued.\nIn all cases, they refer to bonds whose capital repayment is guaranteed by governments.\nLong-term interest rates are one of the determinants of business investment.\nLow long-term interest rates encourage investment in new equipment and high interest rates discourage it.\nInvestment is, in turn, a major source of economic growth.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.long_term_interest_rate(provider='oecd')\nobb.economy.long_term_interest_rate(country=all, frequency=quarterly, provider='oecd')\n```\n\n",
Expand Down Expand Up @@ -8050,8 +8050,8 @@
},
"/economy/immediate_interest_rate": {
"deprecated": {
"flag": null,
"message": null
"flag": true,
"message": "This endpoint will be removed in a future version. Use, `/economy/interest_rates`, instead. Deprecated in OpenBB Platform V4.3 to be removed in V4.5."
},
"description": "Get immediate interest rates by country.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.immediate_interest_rate(provider='oecd')\n# Multiple countries can be passed in as a list.\nobb.economy.immediate_interest_rate(country='united_kingdom,germany', frequency=monthly, provider='oecd')\n```\n\n",
Expand Down Expand Up @@ -8218,6 +8218,126 @@
},
"model": "ImmediateInterestRate"
},
"/economy/interest_rates": {
"deprecated": {
"flag": null,
"message": null
},
"description": "Get interest rates by country(s) and duration.\nMost OECD countries publish short-term, a long-term, and immediate rates monthly.",
"examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.economy.interest_rates(provider='oecd')\n# For OECD, duration can be 'immediate', 'short', or 'long'. Default is 'short', which is the 3-month rate. Overnight interbank rate is 'immediate', and 10-year rate is 'long'.\nobb.economy.interest_rates(provider='oecd', country='all', duration=immediate, frequency=quarter)\n# Multiple countries can be passed in as a list.\nobb.economy.interest_rates(duration=long, country='united_kingdom,germany', frequency=monthly, provider='oecd')\n```\n\n",
"parameters": {
"standard": [
{
"name": "country",
"type": "Union[str, List[str]]",
"description": "The country to get data. Multiple items allowed for provider(s): oecd.",
"default": "united_states",
"optional": true,
"choices": null
},
{
"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
},
{
"name": "provider",
"type": "Literal['oecd']",
"description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: oecd.",
"default": null,
"optional": true
}
],
"oecd": [
{
"name": "duration",
"type": "Literal['immediate', 'short', 'long']",
"description": "Duration of the interest rate. 'immediate' is the overnight rate, 'short' is the 3-month rate, and 'long' is the 10-year rate.",
"default": "short",
"optional": true,
"choices": null
},
{
"name": "frequency",
"type": "Literal['monthly', 'quarter', 'annual']",
"description": "Frequency to get interest rate for for.",
"default": "monthly",
"optional": true,
"choices": null
}
]
},
"returns": {
"OBBject": [
{
"name": "results",
"type": "List[CountryInterestRates]",
"description": "Serializable results."
},
{
"name": "provider",
"type": "Optional[Literal['oecd']]",
"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": "date",
"type": "date",
"description": "The date of the data.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "value",
"type": "float",
"description": "The interest rate value.",
"default": null,
"optional": true,
"choices": null
},
{
"name": "country",
"type": "str",
"description": "Country for which the interest rate is given.",
"default": null,
"optional": true,
"choices": null
}
],
"oecd": []
},
"model": "CountryInterestRates"
},
"/economy/retail_prices": {
"deprecated": {
"flag": null,
Expand Down Expand Up @@ -26721,8 +26841,8 @@
"name": "name",
"type": "str",
"description": "Name of the company.",
"default": "",
"optional": false,
"default": null,
"optional": true,
"choices": null
}
],
Expand Down
Loading
Loading