summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrique Joaquim <h.joaquim@campus.fct.unl.pt>2024-02-05 11:46:37 +0000
committerGitHub <noreply@github.com>2024-02-05 11:46:37 +0000
commit52ac1758f3463cc7523303f614fad7b51029b68f (patch)
treef4289c98e6e5d27f56d084637aa1e343aad9914b
parentb4649b375e120bd2e677b7f3939b8cb8e2a05b1f (diff)
Improve UX for `obb.news` (#5986)
* adding date,start_date and end_date to std params * add date to special params which should've another type * change types to dateType * change helper to accomadate changes in types * date filtering * using the date filtering for all providers * date params on the std model instead * adding the right type * filtering dates on world news * integration tests * fix descriptions * static assets * black * Revert "black" This reverts commit 7288b59f87e1b0816733a96ce77fb96e13dcf0e3. * lint * addressing @montezdesousa suggestion: removing qua 31 jan 2024 15:01:20 WET from standard models and using it only on benzing * tests accordingly * static assets * black --------- Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: teh_coderer <me@tehcoderer.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
-rw-r--r--openbb_platform/core/openbb_core/app/static/package_builder.py1
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/company_news.py31
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/world_news.py31
-rw-r--r--openbb_platform/core/openbb_core/provider/utils/helpers.py25
-rw-r--r--openbb_platform/extensions/news/integration/test_news_api.py33
-rw-r--r--openbb_platform/extensions/news/integration/test_news_python.py24
-rw-r--r--openbb_platform/openbb/package/equity_ownership.py2
-rw-r--r--openbb_platform/openbb/package/fixedincome_corporate.py2
-rw-r--r--openbb_platform/openbb/package/fixedincome_government.py2
-rw-r--r--openbb_platform/openbb/package/news.py55
-rw-r--r--openbb_platform/providers/benzinga/openbb_benzinga/models/company_news.py20
-rw-r--r--openbb_platform/providers/benzinga/openbb_benzinga/models/world_news.py20
-rw-r--r--openbb_platform/providers/biztoc/openbb_biztoc/models/world_news.py5
-rw-r--r--openbb_platform/providers/fmp/openbb_fmp/models/company_news.py5
-rw-r--r--openbb_platform/providers/fmp/openbb_fmp/models/world_news.py6
-rw-r--r--openbb_platform/providers/intrinio/openbb_intrinio/models/company_news.py5
-rw-r--r--openbb_platform/providers/intrinio/openbb_intrinio/models/world_news.py5
-rw-r--r--openbb_platform/providers/polygon/openbb_polygon/models/company_news.py6
-rw-r--r--openbb_platform/providers/tiingo/openbb_tiingo/models/company_news.py6
-rw-r--r--openbb_platform/providers/tiingo/openbb_tiingo/models/world_news.py6
-rw-r--r--openbb_platform/providers/yfinance/openbb_yfinance/models/company_news.py6
21 files changed, 231 insertions, 65 deletions
diff --git a/openbb_platform/core/openbb_core/app/static/package_builder.py b/openbb_platform/core/openbb_core/app/static/package_builder.py
index cd94b48fec8..8b6f14d3fdf 100644
--- a/openbb_platform/core/openbb_core/app/static/package_builder.py
+++ b/openbb_platform/core/openbb_core/app/static/package_builder.py
@@ -524,6 +524,7 @@ class MethodDefinition:
"data": DataProcessingSupportedTypes,
"start_date": str,
"end_date": str,
+ "date": str,
"provider": None,
}
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/company_news.py b/openbb_platform/core/openbb_core/provider/standard_models/company_news.py
index 7f529802728..50cb0066a20 100644
--- a/openbb_platform/core/openbb_core/provider/standard_models/company_news.py
+++ b/openbb_platform/core/openbb_core/provider/standard_models/company_news.py
@@ -1,8 +1,12 @@
"""Company News Standard Model."""
-from datetime import datetime
+from datetime import (
+ date as dateType,
+ datetime,
+)
from typing import Optional
+from dateutil.relativedelta import relativedelta
from pydantic import Field, NonNegativeInt, field_validator
from openbb_core.provider.abstract.data import Data
@@ -24,13 +28,36 @@ class CompanyNewsQueryParams(QueryParams):
limit: Optional[NonNegativeInt] = Field(
default=20, description=QUERY_DESCRIPTIONS.get("limit", "")
)
+ 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("symbols", mode="before")
@classmethod
- def symbols_validate(cls, v: str): # pylint: disable=E0213
+ def symbols_validate(cls, v: str) -> str: # pylint: disable=E0213
"""Validate the symbols."""
return v.upper()
+ @field_validator("start_date", mode="before")
+ @classmethod
+ def start_date_validate(cls, v) -> dateType: # pylint: disable=E0213
+ """Populate start date if empty."""
+ if not v:
+ now = datetime.now().date()
+ v = now - relativedelta(years=1)
+ return v
+
+ @field_validator("end_date", mode="before")
+ @classmethod
+ def end_date_validate(cls, v) -> dateType: # pylint: disable=E0213
+ """Populate end date if empty."""
+ if not v:
+ v = datetime.now().date()
+ return v
+
class CompanyNewsData(Data):
"""Company News Data."""
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/world_news.py b/openbb_platform/core/openbb_core/provider/standard_models/world_news.py
index ea521c82538..36949c754cc 100644
--- a/openbb_platform/core/openbb_core/provider/standard_models/world_news.py
+++ b/openbb_platform/core/openbb_core/provider/standard_models/world_news.py
@@ -1,9 +1,13 @@
"""World News Standard Model."""
-from datetime import datetime
+from datetime import (
+ date as dateType,
+ datetime,
+)
from typing import Dict, List, Optional
-from pydantic import Field, NonNegativeInt
+from dateutil.relativedelta import relativedelta
+from pydantic import Field, NonNegativeInt, field_validator
from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
@@ -21,6 +25,29 @@ class WorldNewsQueryParams(QueryParams):
description=QUERY_DESCRIPTIONS.get("limit", "")
+ " Here its the no. of articles to return.",
)
+ 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("start_date", mode="before")
+ @classmethod
+ def start_date_validate(cls, v) -> dateType: # pylint: disable=E0213
+ """Populate start date if empty."""
+ if not v:
+ now = datetime.now().date()
+ v = now - relativedelta(years=1)
+ return v
+
+ @field_validator("end_date", mode="before")
+ @classmethod
+ def end_date_validate(cls, v) -> dateType: # pylint: disable=E0213
+ """Populate end date if empty."""
+ if not v:
+ v = datetime.now().date()
+ return v
class WorldNewsData(Data):
diff --git a/openbb_platform/core/openbb_core/provider/utils/helpers.py b/openbb_platform/core/openbb_core/provider/utils/helpers.py
index 53d984e55fe..e1977ea8ac7 100644
--- a/openbb_platform/core/openbb_core/provider/utils/helpers.py
+++ b/openbb_platform/core/openbb_core/provider/utils/helpers.py
@@ -2,6 +2,7 @@
import asyncio
import re
+from datetime import datetime
from functools import partial
from inspect import iscoroutinefunction
from typing import Awaitable, Callable, List, Literal, Optional, TypeVar, Union, cast
@@ -10,6 +11,7 @@ import requests
from anyio import start_blocking_portal
from typing_extensions import ParamSpec
+from openbb_core.provider.abstract.data import Data
from openbb_core.provider.utils.client import (
ClientResponse,
ClientSession,
@@ -63,8 +65,8 @@ async def amake_request(
] = None,
**kwargs,
) -> Union[dict, List[dict]]:
- """Abstract helper to make requests from a url with potential headers and params.
-
+ """
+ Abstract helper to make requests from a url with potential headers and params.
Parameters
----------
@@ -232,7 +234,6 @@ async def maybe_coroutine(
func: Callable[P, Union[T, Awaitable[T]]], /, *args: P.args, **kwargs: P.kwargs
) -> T:
"""Check if a function is a coroutine and run it accordingly."""
-
if not iscoroutinefunction(func):
return cast(T, func(*args, **kwargs))
@@ -243,7 +244,6 @@ def run_async(
func: Callable[P, Awaitable[T]], /, *args: P.args, **kwargs: P.kwargs
) -> T:
"""Run a coroutine function in a blocking context."""
-
if not iscoroutinefunction(func):
return cast(T, func(*args, **kwargs))
@@ -252,3 +252,20 @@ def run_async(
return portal.call(partial(func, *args, **kwargs))
finally:
portal.call(portal.stop)
+
+
+def filter_by_dates(
+ data: List[Data],
+ start_date: datetime,
+ end_date: datetime,
+) -> List[Data]:
+ """Filter data by dates."""
+ if not any([start_date, end_date]):
+ return data
+
+ return list(
+ filter(
+ lambda d: start_date <= d.date.date() <= end_date,
+ data,
+ )
+ )
diff --git a/openbb_platform/extensions/news/integration/test_news_api.py b/openbb_platform/extensions/news/integration/test_news_api.py
index fd120956a67..67d476e8207 100644
--- a/openbb_platform/extensions/news/integration/test_news_api.py
+++ b/openbb_platform/extensions/news/integration/test_news_api.py
@@ -26,8 +26,8 @@ def headers():
{
"display": "full",
"date": None,
- "start_date": "2023-01-01",
- "end_date": "2023-06-06",
+ "start_date": None,
+ "end_date": None,
"updated_since": None,
"published_since": None,
"sort": "created",
@@ -46,12 +46,16 @@ def headers():
{
"provider": "fmp",
"limit": 30,
+ "start_date": None,
+ "end_date": None,
}
),
(
{
"provider": "intrinio",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -61,6 +65,8 @@ def headers():
"tag": "federalreserve",
"source": "bloomberg",
"term": "MSFT",
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -68,6 +74,8 @@ def headers():
"provider": "tiingo",
"limit": 30,
"source": "bloomberg.com",
+ "start_date": None,
+ "end_date": None,
}
),
],
@@ -86,7 +94,16 @@ def test_news_world(params, headers):
@parametrize(
"params",
[
- ({"symbols": "AAPL", "limit": 20, "provider": "benzinga"}),
+ (
+ {
+ "symbols": "AAPL",
+ "limit": 20,
+ "provider": "benzinga",
+ "date": "2023-01-01",
+ "start_date": "2023-01-01",
+ "end_date": "2023-06-06",
+ }
+ ),
(
{
"display": "full",
@@ -115,6 +132,8 @@ def test_news_world(params, headers):
"provider": "polygon",
"symbols": "AAPL",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -123,6 +142,8 @@ def test_news_world(params, headers):
"symbols": "AAPL",
"limit": 20,
"page": 1,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -130,6 +151,8 @@ def test_news_world(params, headers):
"provider": "yfinance",
"symbols": "AAPL",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -137,6 +160,8 @@ def test_news_world(params, headers):
"provider": "intrinio",
"symbols": "AAPL",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -145,6 +170,8 @@ def test_news_world(params, headers):
"symbols": "AAPL,MSFT",
"limit": 20,
"source": "bloomberg.com",
+ "start_date": None,
+ "end_date": None,
}
),
],
diff --git a/openbb_platform/extensions/news/integration/test_news_python.py b/openbb_platform/extensions/news/integration/test_news_python.py
index dcfa212c08c..81c26d02dcd 100644
--- a/openbb_platform/extensions/news/integration/test_news_python.py
+++ b/openbb_platform/extensions/news/integration/test_news_python.py
@@ -45,12 +45,16 @@ def obb(pytestconfig): # pylint: disable=inconsistent-return-statements
{
"provider": "fmp",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
{
"provider": "intrinio",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -60,6 +64,8 @@ def obb(pytestconfig): # pylint: disable=inconsistent-return-statements
"tag": "federalreserve",
"source": "bloomberg",
"term": "MSFT",
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -67,6 +73,8 @@ def obb(pytestconfig): # pylint: disable=inconsistent-return-statements
"provider": "tiingo",
"limit": 30,
"source": "bloomberg.com",
+ "start_date": None,
+ "end_date": None,
}
),
],
@@ -85,8 +93,8 @@ def test_news_world(params, obb):
{
"display": "full",
"date": None,
- "start_date": "2023-01-01",
- "end_date": "2023-06-06",
+ "start_date": None,
+ "end_date": None,
"updated_since": None,
"published_since": None,
"sort": "created",
@@ -104,11 +112,13 @@ def test_news_world(params, obb):
),
(
{
- "published_utc": "2023-01-10",
+ "published_utc": "2024-01-10",
"order": "desc",
"provider": "polygon",
"symbols": "AAPL",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -117,6 +127,8 @@ def test_news_world(params, obb):
"symbols": "AAPL",
"limit": 20,
"page": 1,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -124,6 +136,8 @@ def test_news_world(params, obb):
"provider": "yfinance",
"symbols": "AAPL",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -131,6 +145,8 @@ def test_news_world(params, obb):
"provider": "intrinio",
"symbols": "AAPL",
"limit": 20,
+ "start_date": None,
+ "end_date": None,
}
),
(
@@ -139,6 +155,8 @@ def test_news_world(params, obb):
"symbols": "AAPL,MSFT",
"limit": 20,
"source": "bloomberg.com",
+ "start_date": None,
+ "end_date": None,
}
),
],
diff --git a/openbb_platform/openbb/package/equity_ownership.py b/openbb_platform/openbb/package/equity_ownership.py
index 726c71f75d4..76a13ae1f0b 100644
--- a/openbb_platform/openbb/package/equity_ownership.py
+++ b/openbb_platform/openbb/package/equity_ownership.py
@@ -315,7 +315,7 @@ class ROUTER_equity_ownership(Container):
OpenBBCustomParameter(description="Symbol to get data for."),
],
date: Annotated[
- Optional[datetime.date],
+ Union[datetime.date, None, str],
OpenBBCustomParameter(description="A specific date to get data for."),
] = None,
page: Annotated[
diff --git a/openbb_platform/openbb/package/fixedincome_corporate.py b/openbb_platform/openbb/package/fixedincome_corporate.py
index 9c6eef19c94..44dd1885ffb 100644
--- a/openbb_platform/openbb/package/fixedincome_corporate.py
+++ b/openbb_platform/openbb/package/fixedincome_corporate.py
@@ -125,7 +125,7 @@ class ROUTER_fixedincome_corporate(Container):
def hqm(
self,
date: Annotated[
- Optional[datetime.date],
+ Union[datetime.date, None, str],
OpenBBCustomParameter(description="A specific date to get data for."),
] = None,
yield_curve: Annotated[
diff --git a/openbb_platform/openbb/package/fixedincome_government.py b/openbb_platform/openbb/package/fixedincome_government.py
index 81f311babbd..06104f70ef1 100644
--- a/openbb_platform/openbb/package/fixedincome_government.py
+++ b/openbb_platform/openbb/package/fixedincome_government.py
@@ -118,7 +118,7 @@ class ROUTER_fixedincome_government(Container):
def us_yield_curve(
self,
date: Annotated[
- Optional[datetime.date],
+ Union[datetime.date, None, str],
OpenBBCustomParameter(
description="A specific date to get data for. Defaults to the most recent FRED entry."
),
diff --git a/openbb_platform/openbb/package/news.py b/openbb_platform/openbb/package/news.py
index 338bb2a8e72..2cb27f60f28 100644
--- a/openbb_platform/openbb/package/news.py
+++ b/openbb_platform/openbb/package/news.py
@@ -1,6 +1,7 @@
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
-from typing import Literal, Optional
+import datetime
+from typing import Literal, Optional, Union
from annotated_types import Ge
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
@@ -33,6 +34,18 @@ class ROUTER_news(Container):
Optional[Annotated[int, Ge(ge=0)]],
OpenBBCustomParameter(description="The number of data entries to return."),
] = 20,
+ start_date: Annotated[
+ Union[datetime.date, None, str],
+ OpenBBCustomParameter(
+ description="Start date of the data, in YYYY-MM-DD format."
+ ),
+ ] = None,
+ end_date: Annotated[
+ Union[datetime.date, None, str],
+ OpenBBCustomParameter(
+ description="End date of the data, in YYYY-MM-DD format."
+ ),
+ ] = None,
provider: Optional[
Literal["benzinga", "fmp", "intrinio", "polygon", "tiingo", "yfinance"]
] = None,
@@ -46,18 +59,18 @@ class ROUTER_news(Container):
Here it is a separated list of symbols.
limit : Optional[Annotated[int, Ge(ge=0)]]
The number of data entries to return.
+ start_date : Optional[datetime.date]
+ Start date of the data, in YYYY-MM-DD format.
+ end_date : Optional[datetime.date]
+ End date of the data, in YYYY-MM-DD format.
provider : Optional[Literal['benzinga', 'fmp', 'intrinio', 'polygon', 'tiing...
The provider to use for the query, by default None.
If None, the provider specified in defaults is selected or 'benzinga' if there is
no default.
+ date : Optional[datetime.date]
+ A specific date to get data for. (provider: benzinga)
display : Literal['headline', 'abstract', 'full']
Specify headline only (headline), headline + teaser (abstract), or headline + full body (full). (provider: benzinga)
- date : Optional[str]
- Date of the news to retrieve. (provider: benzinga)
- start_date : Optional[str]
- Start date of the news to retrieve. (provider: benzinga)
- end_date : Optional[str]
- End date of the news to retrieve. (provider: benzinga)
updated_since : Optional[int]
Number of seconds since the news was updated. (provider: benzinga)
published_since : Optional[int]
@@ -167,6 +180,8 @@ class ROUTER_news(Container):
standard_params={
"symbols": symbols,
"limit": limit,
+ "start_date": start_date,
+ "end_date": end_date,
},
extra_params=kwargs,
)
@@ -181,6 +196,18 @@ class ROUTER_news(Container):
description="The number of data entries to return. Here its the no. of articles to return."
),
] = 20,
+ start_date: Annotated[
+ Union[datetime.date, None, str],
+ OpenBBCustomParameter(
+ description="Start date of the data, in YYYY-MM-DD format."
+ ),
+ ] = None,
+ end_date: Annotated[
+ Union[datetime.date, None, str],
+ OpenBBCustomParameter(
+ description="End date of the data, in YYYY-MM-DD format."
+ ),
+ ] = None,
provider: Optional[Literal["benzinga", "fmp", "intrinio", "tiingo"]] = None,
**kwargs
) -> OBBject:
@@ -190,18 +217,18 @@ class ROUTER_news(Container):
----------
limit : int
The number of data entries to return. Here its the no. of articles to return.
+ start_date : Optional[datetime.date]
+ Start date of the data, in YYYY-MM-DD format.
+ end_date : Optional[datetime.date]
+ End date of the data, in YYYY-MM-DD format.
provider : Optional[Literal['benzinga', 'fmp', 'intrinio', 'tiingo']]
The provider to use for the query, by default None.
If None, the provider specified in defaults is selected or 'benzinga' if there is
no default.
+ date : Optional[datetime.date]
+ A specific date to get data for. (provider: benzinga)
display : Literal['headline', 'abstract', 'full']
Specify headline only (headline), headline + teaser (abstract), or headline + full body (full). (provider: benzinga)
- date : Optional[str]
- Date of the news to retrieve. (provider: benzinga)
- start_date : Optional[str]
- Start date of the news to retrieve. (provider: benzinga)
- end_date : Optional[str]
- End date of the news to retrieve. (provider: benzinga)
updated_since : Optional[int]
Number of seconds since the news was updated. (provider: benzinga)
published_since : Optional[int]
@@ -290,6 +317,8 @@ class ROUTER_news(Container):
},
standard_params={
"limit": limit,
+ "start_date": start_date,
+ "end_date": end_date,
},
extra_params=kwargs,
)
diff --git a/openbb_platform/providers/benzinga/openbb_benzinga/models/company_news.py b/openbb_platform/providers/benzinga/openbb_benzinga/models/company_news.py
index 5e865f3dc23..5888217c4de 100644
--- a/openbb_platform/providers/benzinga/openbb_benzinga/models/company_news.py
+++ b/