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

Adding OECD Endpoints (CPI + Share Price Index) #6157

Merged
merged 45 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e84379c
remove ultima + althub
jmaslek Feb 27, 2024
8b68f23
move twitter keys
jmaslek Feb 27, 2024
6a8a1ea
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Feb 29, 2024
86080bb
Enhance caching + more specific urls
jmaslek Feb 29, 2024
37e0cae
Merge branch 'develop' into feature/cleanup-oecd
jmaslek Feb 29, 2024
8cf48d9
Update urls for stir
jmaslek Feb 29, 2024
4dc2be6
LTIR
jmaslek Feb 29, 2024
ea429d5
cli
jmaslek Feb 29, 2024
4999a96
Merge branch 'develop' into feature/cleanup-oecd
jmaslek Feb 29, 2024
fd23ca4
one v3 file to fix
jmaslek Feb 29, 2024
6da6c22
Typing edits + gdp dates + gdp all countries
jmaslek Feb 29, 2024
3252bfe
Tests
jmaslek Feb 29, 2024
41376e8
Merge branch 'develop' into feature/cleanup-oecd
jmaslek Feb 29, 2024
ae28bd1
lint
jmaslek Feb 29, 2024
9781cae
not sure why those didnt record
jmaslek Feb 29, 2024
aa9bb4e
handle the fact that we artifically add some start dates and end dates
jmaslek Feb 29, 2024
40159f2
fix dates with actual solution not weird patch
jmaslek Feb 29, 2024
beceaa6
lint
jmaslek Feb 29, 2024
cef17db
Add CPI from OECD
jmaslek Mar 1, 2024
f356a58
coment
jmaslek Mar 1, 2024
2928da1
Add Share Price endpoint
jmaslek Mar 1, 2024
010562f
Merge branch 'develop' into feature/oecd-cpi
jmaslek Mar 1, 2024
3d23f4a
Merge branch 'develop' into feature/oecd-cpi
jmaslek Mar 4, 2024
21cc561
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 11, 2024
9f9cba3
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 12, 2024
58d48db
finish merge
jmaslek Mar 12, 2024
c1d518a
Clean up the CPI oecd model with the choices and allow expensitures t…
jmaslek Mar 12, 2024
0b10f07
commit this change
jmaslek Mar 12, 2024
895b20a
remove "share prices"
jmaslek Mar 12, 2024
2319164
Correctly handle country "choices" and let oecd do multiple countries
jmaslek Mar 12, 2024
59591e3
Merge branch 'develop' into feature/oecd-cpi
deeleeramone Mar 18, 2024
c7f3d9a
merge conflicts
deeleeramone May 27, 2024
1be0a8d
some fixes
deeleeramone May 28, 2024
0929203
standard model fields
deeleeramone May 28, 2024
1b93b4b
unit test
deeleeramone May 28, 2024
0ef8ee8
frequency in standard model
deeleeramone May 28, 2024
064a864
empty fred
deeleeramone May 28, 2024
4144c35
format oecd dates as period beginning
deeleeramone May 28, 2024
bc6bf77
fred -> when frequency is annual, the transform needs to be same peri…
deeleeramone May 28, 2024
8e81772
test thing
deeleeramone May 28, 2024
50d48b2
add share price index
deeleeramone May 28, 2024
aceba77
test params
deeleeramone May 28, 2024
5d3cddb
merge branch develop
deeleeramone May 29, 2024
775cba2
better parsing with CSV response
deeleeramone May 29, 2024
7b77f0a
update test cassette
deeleeramone May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""CPI Standard Model."""

from datetime import date as dateType
from typing import Literal, Optional

from pydantic import Field, field_validator

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 ConsumerPriceIndexQueryParams(QueryParams):
"""CPI Query."""

country: str = Field(
description=QUERY_DESCRIPTIONS.get("country"),
default="united_states",
)
transform: Literal["index", "yoy", "period"] = Field(
description="Transformation of the CPI data. Period represents the change since previous."
+ " Defaults to change from one year ago (yoy).",
default="yoy",
json_schema_extra={"choices": ["index", "yoy", "period"]},
)
frequency: Literal["annual", "quarter", "monthly"] = Field(
default="monthly",
description=QUERY_DESCRIPTIONS.get("frequency"),
json_schema_extra={"choices": ["annual", "quarter", "monthly"]},
)
harmonized: bool = Field(
default=False, description="If true, returns harmonized data."
)
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")
)

@field_validator("country", mode="before", check_fields=False)
@classmethod
def to_lower(cls, v):
"""Convert country to lower case."""
return v.replace(" ", "_").lower()


class ConsumerPriceIndexData(Data):
"""CPI data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date"))
country: str = Field(description=DATA_DESCRIPTIONS.get("country"))
value: float = Field(description="CPI index value or period change.")
128 changes: 0 additions & 128 deletions openbb_platform/core/openbb_core/provider/standard_models/cpi.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Share Price Index Standard Model."""

from datetime import date as dateType
from typing import Literal, 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 SharePriceIndexQueryParams(QueryParams):
"""Share Price Index Query."""

country: str = Field(
description=QUERY_DESCRIPTIONS.get("country", ""),
default="united_states",
)
frequency: Literal["monthly", "quarter", "annual"] = Field(
description=QUERY_DESCRIPTIONS.get("frequency", ""),
default="monthly",
json_schema_extra={"choices": ["monthly", "quarter", "annual"]},
)
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 SharePriceIndexData(Data):
"""Share Price Index Data."""

date: Optional[dateType] = Field(
default=None, description=DATA_DESCRIPTIONS.get("date")
)
country: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("country", ""),
)
value: Optional[float] = Field(
default=None,
description="Share price index value.",
)
48 changes: 43 additions & 5 deletions openbb_platform/extensions/economy/integration/test_economy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,37 @@ def test_economy_calendar(params, headers):
(
{
"country": "spain",
"units": "growth_same",
"frequency": "monthly",
"harmonized": True,
"start_date": "2023-01-01",
"transform": "yoy",
"frequency": "annual",
"harmonized": False,
"start_date": "2020-01-01",
"end_date": "2023-06-06",
"provider": "fred",
}
),
(
{
"country": "portugal,spain",
"units": "growth_same",
"transform": "period",
"frequency": "monthly",
"harmonized": True,
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"provider": "fred",
}
),
(
{
"country": "portugal,spain",
"transform": "yoy",
"frequency": "quarter",
"harmonized": False,
"start_date": "2020-01-01",
"end_date": "2023-06-06",
"provider": "oecd",
"expenditure": "transport",
}
),
],
)
@pytest.mark.integration
Expand Down Expand Up @@ -696,3 +708,29 @@ def test_economy_central_bank_holdings(params, headers):
result = requests.get(url, headers=headers, timeout=5)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@parametrize(
"params",
[
(
{
"country": "united_states,united_kingdom",
"frequency": "monthly",
"provider": "oecd",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
}
),
],
)
@pytest.mark.integration
def test_economy_share_price_index(params, headers):
"""Test the economy share price index."""
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/share_price_index?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,38 @@ def test_economy_calendar(params, obb):
@parametrize(
"params",
[
(
{
"country": "spain",
"transform": "yoy",
"frequency": "annual",
"harmonized": False,
"start_date": "2020-01-01",
"end_date": "2023-06-06",
"provider": "fred",
}
),
(
{
"country": "portugal,spain",
"units": "growth_same",
"transform": "period",
"frequency": "monthly",
"harmonized": True,
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"provider": "fred",
}
),
(
{
"country": "portugal,spain",
"transform": "yoy",
"frequency": "quarter",
"harmonized": False,
"start_date": "2020-01-01",
"end_date": "2023-06-06",
"provider": "oecd",
"expenditure": "transport",
}
),
],
Expand Down Expand Up @@ -644,3 +668,28 @@ def test_economy_central_bank_holdings(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@parametrize(
"params",
[
(
{
"country": "united_states,united_kingdom",
"frequency": "monthly",
"provider": "oecd",
"start_date": "2022-01-01",
"end_date": "2024-04-01",
}
),
],
)
@pytest.mark.integration
def test_economy_share_price_index(params, obb):
"""Test economy share price index."""
params = {p: v for p, v in params.items() if v}

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