fix stock_news alias

This commit is contained in:
Diogo Sousa
2023-07-25 20:21:07 +01:00
parent 5c325744b1
commit 1658974bb6
6 changed files with 151 additions and 156 deletions

View File

@@ -2,9 +2,8 @@
from datetime import datetime
from typing import Dict, List, Optional
from typing import Dict, List, Literal, Optional
from openbb_provider.abstract.data import QueryParams
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.helpers import data_transformer, get_querystring
from openbb_provider.models.global_news import GlobalNewsData, GlobalNewsQueryParams
@@ -13,64 +12,71 @@ from pydantic import Field
from openbb_benzinga.utils.helpers import BenzingaBaseNewsData, get_data
class BenzingaGlobalNewsQueryParams(QueryParams):
class BenzingaGlobalNewsQueryParams(GlobalNewsQueryParams):
"""Benzinga Global News query.
Source: https://docs.benzinga.io/benzinga/newsfeed-v2.html
Parameter
---------
page : int (default: 0)
The page of the data to retrieve.
pageSize : int (default: 15)
The number of results to return per page.
displayOutput : str (default: "headline")
The type of data to return. Options are "headline", "summary", "full", "all".
date : Optional[datetime]
The date of the news to retrieve.
dateFrom : Optional[datetime]
The start date of the news to retrieve.
dateTo : Optional[datetime]
The end date of the news to retrieve.
updatedSince : Optional[int]
The number of seconds since the news was updated.
publishedSince : Optional[int]
The number of seconds since the news was published.
sort : Optional[str]
The order in which to sort the news. Options are:
"published_at", "updated_at", "title", "author", "channel", "ticker", "topic", "content_type".
isin : Optional[str]
The ISIN of the news to retrieve.
cusip : Optional[str]
The CUSIP of the news to retrieve.
tickers : Optional[str]
The tickers of the news to retrieve.
channels : Optional[str]
The channels of the news to retrieve.
topics : Optional[str]
The topics of the news to retrieve.
authors : Optional[str]
The authors of the news to retrieve.
content_types : Optional[str]
The content types of the news to retrieve.
"""
page: int = Field(default=0)
pageSize: int = Field(default=15)
displayOutput: str = Field(default="headline")
date: Optional[datetime] = None
dateFrom: Optional[datetime] = None
dateTo: Optional[datetime] = None
updatedSince: Optional[int] = None
publishedSince: Optional[int] = None
sort: Optional[str] = None
isin: Optional[str] = None
cusip: Optional[str] = None
tickers: Optional[str] = None
channels: Optional[str] = None
topics: Optional[str] = None
authors: Optional[str] = None
content_types: Optional[str] = None
pageSize: int = Field(
default=15, description="The number of results to return per page."
)
displayOutput: Literal["headline", "summary", "full", "all"] = Field(
default="headline", description="The type of data to return."
)
date: Optional[datetime] = Field(
default=None, description="The date of the news to retrieve."
)
dateFrom: Optional[datetime] = Field(
default=None, description="The start date of the news to retrieve."
)
dateTo: Optional[datetime] = Field(
default=None, description="The end date of the news to retrieve."
)
updatedSince: Optional[int] = Field(
default=None,
description="The number of seconds since the news was updated.",
)
publishedSince: Optional[int] = Field(
default=None,
description="The number of seconds since the news was published.",
)
sort: Optional[
Literal[
"published_at",
"updated_at",
"title",
"author",
"channel",
"ticker",
"topic",
"content_type",
]
] = Field(
default=None,
description="The order in which to sort the news. Options are: published_at, updated_at, title, author, channel, ticker, topic, content_type.",
)
isin: Optional[str] = Field(
default=None, description="The ISIN of the news to retrieve."
)
cusip: Optional[str] = Field(
default=None, description="The CUSIP of the news to retrieve."
)
tickers: Optional[str] = Field(
default=None, description="The tickers of the news to retrieve."
)
channels: Optional[str] = Field(
default=None, description="The channels of the news to retrieve."
)
topics: Optional[str] = Field(
default=None, description="The topics of the news to retrieve."
)
authors: Optional[str] = Field(
default=None, description="The authors of the news to retrieve."
)
content_types: Optional[str] = Field(
default=None, description="The content types of the news to retrieve."
)
class BenzingaGlobalNewsData(BenzingaBaseNewsData):

View File

@@ -2,9 +2,8 @@
from datetime import datetime
from typing import Dict, List, Optional
from typing import Dict, List, Literal, Optional
from openbb_provider.abstract.data import QueryParams
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.helpers import data_transformer, get_querystring
from openbb_provider.models.stock_news import StockNewsData, StockNewsQueryParams
@@ -13,64 +12,68 @@ from pydantic import Field
from openbb_benzinga.utils.helpers import BenzingaBaseNewsData, get_data
class BenzingaStockNewsQueryParams(QueryParams):
class BenzingaStockNewsQueryParams(StockNewsQueryParams):
"""Benzinga Stock News query.
Source: https://docs.benzinga.io/benzinga/newsfeed-v2.html
Parameter
---------
page : int (default: 0)
The page of the data to retrieve.
symbols: str
The symbols of the companies.
pageSize : int (default: 15)
The number of results to return per page.
headline : str
The type of data to return. Options are "headline", "summary", "full", "all".
date : Optional[datetime]
The date of the news to retrieve.
dateFrom : Optional[datetime]
The start date of the news to retrieve.
dateTo : Optional[datetime]
The end date of the news to retrieve.
updatedSince : Optional[int]
The number of seconds since the news was updated.
publishedSince : Optional[int]
The number of seconds since the news was published.
sort : Optional[str]
The order in which to sort the news. Options are:
"published_at", "updated_at", "title", "author", "channel", "ticker", "topic", "content_type".
isin : Optional[str]
The ISIN of the news to retrieve.
cusip : Optional[str]
The CUSIP of the news to retrieve.
channels : Optional[str]
The channels of the news to retrieve.
topics : Optional[str]
The topics of the news to retrieve.
authors : Optional[str]
The authors of the news to retrieve.
content_types : Optional[str]
The content types of the news to retrieve.
"""
tickers: str = Field(alias="symbols")
page: int = Field(default=0)
pageSize: int = Field(default=15)
displayOutput: str = Field(default="headline")
date: Optional[datetime] = None
dateFrom: Optional[datetime] = None
dateTo: Optional[datetime] = None
updatedSince: Optional[int] = None
publishedSince: Optional[int] = None
sort: Optional[str] = None
isin: Optional[str] = None
cusip: Optional[str] = None
channels: Optional[str] = None
topics: Optional[str] = None
authors: Optional[str] = None
content_types: Optional[str] = None
class Config:
fields = {"symbols": "tickers", "limit": "pageSize"}
displayOutput: Literal["headline", "summary", "full", "all"] = Field(
default="headline", description="The type of data to return."
)
date: Optional[datetime] = Field(
default=None, description="The date of the news to retrieve."
)
dateFrom: Optional[datetime] = Field(
default=None, description="The start date of the news to retrieve."
)
dateTo: Optional[datetime] = Field(
default=None, description="The end date of the news to retrieve."
)
updatedSince: Optional[int] = Field(
default=None,
description="The number of seconds since the news was updated.",
)
publishedSince: Optional[int] = Field(
default=None,
description="The number of seconds since the news was published.",
)
sort: Optional[
Literal[
"published_at",
"updated_at",
"title",
"author",
"channel",
"ticker",
"topic",
"content_type",
]
] = Field(
default=None,
description="The order in which to sort the news. Options are: published_at, updated_at, title, author, channel, ticker, topic, content_type.",
)
isin: Optional[str] = Field(
default=None, description="The ISIN of the news to retrieve."
)
cusip: Optional[str] = Field(
default=None, description="The CUSIP of the news to retrieve."
)
channels: Optional[str] = Field(
default=None, description="The channels of the news to retrieve."
)
topics: Optional[str] = Field(
default=None, description="The topics of the news to retrieve."
)
authors: Optional[str] = Field(
default=None, description="The authors of the news to retrieve."
)
content_types: Optional[str] = Field(
default=None, description="The content types of the news to retrieve."
)
class BenzingaStockNewsData(BenzingaBaseNewsData):
@@ -91,7 +94,7 @@ class BenzingaStockNewsFetcher(
) -> BenzingaStockNewsQueryParams:
return BenzingaStockNewsQueryParams(
page=query.page,
symbols=query.symbols, # type: ignore
tickers=query.symbols, # type: ignore
**extra_params if extra_params else {},
)

View File

@@ -4,33 +4,23 @@
from datetime import datetime
from typing import Dict, List, Optional
from openbb_provider.abstract.data import Data, QueryParams
from openbb_provider.abstract.data import Data
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.helpers import data_transformer
from openbb_provider.models.stock_news import StockNewsData, StockNewsQueryParams
from pydantic import Field, NonNegativeInt
from pydantic import Field
from openbb_fmp.utils.helpers import create_url, get_data_many
class FMPStockNewsQueryParams(QueryParams):
class FMPStockNewsQueryParams(StockNewsQueryParams):
"""FMP Stock News query.
Source: https://site.financialmodelingprep.com/developer/docs/stock-news-api/
Parameter
---------
symbols : str
The symbols of the companies.
page : int (default: 0)
The page of the data to retrieve.
limit : Optional[int]
The limit of the data to retrieve.
"""
tickers: str = Field(min_length=1, alias="symbols")
page: int = Field(default=0)
limit: Optional[NonNegativeInt]
class Config:
fields = {"symbols": "tickers"}
class FMPStockNewsData(Data):
@@ -56,7 +46,7 @@ class FMPStockNewsFetcher(
query: StockNewsQueryParams, extra_params: Optional[Dict] = None
) -> FMPStockNewsQueryParams:
return FMPStockNewsQueryParams(
symbols=query.symbols,
tickers=query.symbols,
page=query.page,
**extra_params if extra_params else {}
)

View File

@@ -84,21 +84,21 @@ def _extract_fields(
provider_dict: Dict = {}
standard_dict: Dict = {}
for field in provider_fields:
provider_dict[provider_fields[field].alias] = {
"type": provider_fields[field].annotation,
"default": provider_fields[field].default,
"required": provider_fields[field].required,
"description": provider_fields[field].field_info.description,
}
for field in standard_fields:
standard_dict[standard_fields[field].alias] = {
"type": standard_fields[field].annotation,
"default": standard_fields[field].default,
"required": standard_fields[field].required,
"description": standard_fields[field].field_info.description,
}
for k, v in provider_fields.items():
if k in standard_fields:
standard_dict[k] = {
"type": v.annotation,
"default": v.default,
"required": v.required,
"description": v.field_info.description,
}
else:
provider_dict[k] = {
"type": v.annotation,
"default": v.default,
"required": v.required,
"description": v.field_info.description,
}
return provider_dict, standard_dict

View File

@@ -4,11 +4,11 @@
from datetime import date
from typing import Optional
from pydantic import Field
from openbb_provider.abstract.data import Data, QueryParams
from openbb_provider.models.base import BaseSymbol
from pydantic import Field
class CompanyOverviewQueryParams(QueryParams, BaseSymbol):
"""Company overview Query."""

View File

@@ -4,28 +4,24 @@
from datetime import date
from typing import Optional
from pydantic import Field, validator
from pydantic import Field, NonNegativeInt, validator
from openbb_provider.abstract.data import Data, QueryParams
from openbb_provider.metadata import QUERY_DESCRIPTIONS
class StockNewsQueryParams(QueryParams):
"""Stock news query.
Parameter
---------
symbols : str
The symbols of the company.
page : int
The page of the stock news to be retrieved.
"""
"""Stock news query."""
symbols: str = Field(
min_length=1, description=QUERY_DESCRIPTIONS.get("symbols", "")
)
page: int = Field(default=0)
page: int = Field(
default=0, description="The page of the stock news to be retrieved."
)
limit: Optional[NonNegativeInt] = Field(
default=15, description="The number of results to return per page."
)
@validator("symbols", pre=True)
def time_validate(cls, v: str): # pylint: disable=E0213