Files
OpenBB/openbb_platform/openbb/package/news.py
montezdesousa f328a45b95 [Feature] - refactor examples (#6154)
* remove auto examples and split python from api

* add missing exampels

* rebuild

* query params focstring

* black

* add scoped examples

* group model imports in the router

* unblock api

* fix

* classify examples

* fix package identation

* black sig

* fix indentation without linter

* fix python examples

* remove doc

* pylint

* again

* add model validators

* commodity, crypto, currency

* filter examples

* fix python examples

* fix filter and build

* undo toml change

* add comment

* oop

* comment

* typing

* lint

* Update router.py

* Update econometrics_router.py

* fix to_python

* to_python

* to_python

* black

* fix multiple line field descriptions

* remove circular import

* add missing import

* pass indent as object attr

* doc

* doc

* this looks better

* forgot this

* fix: new examples adapted

* fix prev commit

* avoid future problems

* Update ownership_router.py

* rebuild + remove todo

* make description mandatory for python examples

* simple indent

* append_examples func works for both website and docstring

* Add example unit tests

* Edit example unit tests

* fix validator

* this works

* fix to_python

* fix mandatory docstrings

* typing

* shorter error msgs

* economy router

* fix more examples

* more examples

* more examples

* more examples

* field desc

* minor fix

* fix etf examples

* handling types better

* lint

* rename method

* rename var

* docstring + move method

* typing

* prompt

* rebuild

* prompt fix in PythonEx

* fix examples without model

* example mock data

* add get_field_type func to get field data type

* panel data

* mock data

* fix

* fix

* docstring

* ohlcv

* pylint

* quantitaive router

* simplify mock data

* fix remaining quantitative routers

* a bit more flexibility for examples

* lint

* mock dat from sample

* docstring

* assertion

* bugfix

* minor fix

* technical

* fix integration tests

* fix docstring

* econometrics examples

* econometrics examples

* remove warning

* add technical examples

* fix bad examples

* fix more examples

* update test rules

* remoce old pydantic referenc

* fix bug in treasury prices

* fix quantitative examples

* discovery router

* equity shorts

* equity shorts

* fix currency pairs

* fix sec_router example

* fix panel data to support all funcs

* black

* more examples fixes

* simplify test

* rebuild

* test doc

* add provider to some ex

* ^

* last

* add provider

* rebuild

* working examples

* noqa

* pylint

* pylint

* clean

* minor fix

* fix test

* lint

* ruff

---------

Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
2024-03-09 23:22:40 +00:00

375 lines
15 KiB
Python

### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
import datetime
from typing import List, Literal, Optional, Union
from annotated_types import Ge
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.static.container import Container
from openbb_core.app.static.utils.decorators import exception_handler, validate
from openbb_core.app.static.utils.filters import filter_inputs
from typing_extensions import Annotated
class ROUTER_news(Container):
"""/news
company
world
"""
def __repr__(self) -> str:
return self.__doc__ or ""
@exception_handler
@validate
def company(
self,
symbol: Annotated[
Union[str, None, List[Optional[str]]],
OpenBBCustomParameter(
description="Symbol to get data for. This endpoint will accept multiple symbols separated by commas. Multiple items allowed for provider(s): benzinga, fmp, intrinio, polygon, tiingo, yfinance."
),
] = None,
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,
limit: Annotated[
Optional[Annotated[int, Ge(ge=0)]],
OpenBBCustomParameter(description="The number of data entries to return."),
] = 2500,
provider: Annotated[
Optional[
Literal["benzinga", "fmp", "intrinio", "polygon", "tiingo", "yfinance"]
],
OpenBBCustomParameter(
description="The provider to use for the query, by default None.\n If None, the provider specified in defaults is selected or 'benzinga' if there is\n no default."
),
] = None,
**kwargs
) -> OBBject:
"""Company News. Get news for one or more companies.
Parameters
----------
symbol : Union[str, None, List[Optional[str]]]
Symbol to get data for. This endpoint will accept multiple symbols separated by commas. Multiple items allowed for provider(s): benzinga, fmp, intrinio, polygon, tiingo, yfinance.
start_date : Union[datetime.date, None, str]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None, str]
End date of the data, in YYYY-MM-DD format.
limit : Optional[Annotated[int, Ge(ge=0)]]
The number of data entries to return.
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)
updated_since : Optional[int]
Number of seconds since the news was updated. (provider: benzinga)
published_since : Optional[int]
Number of seconds since the news was published. (provider: benzinga)
sort : Literal['id', 'created', 'updated']
Key to sort the news by. (provider: benzinga)
order : Optional[Literal['asc', 'desc']]
Order to sort the news by. (provider: benzinga);
Sort order of the articles. (provider: polygon)
isin : Optional[str]
The company's ISIN. (provider: benzinga)
cusip : Optional[str]
The company's CUSIP. (provider: benzinga)
channels : Optional[str]
Channels of the news to retrieve. (provider: benzinga)
topics : Optional[str]
Topics of the news to retrieve. (provider: benzinga)
authors : Optional[str]
Authors of the news to retrieve. (provider: benzinga)
content_types : Optional[str]
Content types of the news to retrieve. (provider: benzinga)
page : Optional[int]
Page number of the results. Use in combination with limit. (provider: fmp)
offset : Optional[int]
Page offset, used in conjunction with limit. (provider: tiingo)
source : Optional[str]
A comma-separated list of the domains requested. (provider: tiingo)
Returns
-------
OBBject
results : List[CompanyNews]
Serializable results.
provider : Optional[Literal['benzinga', 'fmp', 'intrinio', 'polygon', 'tiingo', 'yfinance']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.
CompanyNews
-----------
date : datetime
The date of the data. Here it is the published date of the article.
title : str
Title of the article.
text : Optional[str]
Text/body of the article.
images : Optional[List[Dict[str, str]]]
Images associated with the article.
url : str
URL to the article.
symbols : Optional[str]
Symbols associated with the article.
id : Optional[str]
Article ID. (provider: benzinga, intrinio, polygon)
author : Optional[str]
Author of the article. (provider: benzinga)
teaser : Optional[str]
Teaser of the news. (provider: benzinga)
channels : Optional[str]
Channels associated with the news. (provider: benzinga)
stocks : Optional[str]
Stocks associated with the news. (provider: benzinga)
tags : Optional[str]
Tags associated with the news. (provider: benzinga, polygon, tiingo)
updated : Optional[datetime]
Updated date of the news. (provider: benzinga)
source : Optional[str]
Name of the news source. (provider: fmp);
Source of the article. (provider: polygon);
News source. (provider: tiingo);
Source of the news article (provider: yfinance)
amp_url : Optional[str]
AMP URL. (provider: polygon)
publisher : Optional[openbb_polygon.models.company_news.PolygonPublisher]
Publisher of the article. (provider: polygon)
article_id : Optional[int]
Unique ID of the news article. (provider: tiingo)
crawl_date : Optional[datetime]
Date the news article was crawled. (provider: tiingo)
Examples
--------
>>> from openbb import obb
>>> obb.news.company(provider='benzinga')
>>> obb.news.company(limit=100, provider='benzinga')
>>> # Get news on the specified dates.
>>> obb.news.company(symbol='AAPL', start_date='2024-02-01', end_date='2024-02-07', provider='intrinio')
>>> # Display the headlines of the news.
>>> obb.news.company(symbol='AAPL', display='headline', provider='benzinga')
>>> # Get news for multiple symbols.
>>> obb.news.company(symbol='aapl,tsla', provider='fmp')
>>> # Get news company's ISIN.
>>> obb.news.company(symbol='NVDA', isin='US0378331005', provider='benzinga')
""" # noqa: E501
return self._run(
"/news/company",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"/news/company",
(
"benzinga",
"fmp",
"intrinio",
"polygon",
"tiingo",
"yfinance",
),
)
},
standard_params={
"symbol": symbol,
"start_date": start_date,
"end_date": end_date,
"limit": limit,
},
extra_params=kwargs,
extra_info={
"symbol": {
"multiple_items_allowed": [
"benzinga",
"fmp",
"intrinio",
"polygon",
"tiingo",
"yfinance",
]
}
},
)
)
@exception_handler
@validate
def world(
self,
limit: Annotated[
int,
OpenBBCustomParameter(
description="The number of data entries to return. The number of articles to return."
),
] = 2500,
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: Annotated[
Optional[Literal["benzinga", "fmp", "intrinio", "tiingo"]],
OpenBBCustomParameter(
description="The provider to use for the query, by default None.\n If None, the provider specified in defaults is selected or 'benzinga' if there is\n no default."
),
] = None,
**kwargs
) -> OBBject:
"""World News. Global news data.
Parameters
----------
limit : int
The number of data entries to return. The number of articles to return.
start_date : Union[datetime.date, None, str]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None, str]
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)
updated_since : Optional[int]
Number of seconds since the news was updated. (provider: benzinga)
published_since : Optional[int]
Number of seconds since the news was published. (provider: benzinga)
sort : Literal['id', 'created', 'updated']
Key to sort the news by. (provider: benzinga)
order : Literal['asc', 'desc']
Order to sort the news by. (provider: benzinga)
isin : Optional[str]
The ISIN of the news to retrieve. (provider: benzinga)
cusip : Optional[str]
The CUSIP of the news to retrieve. (provider: benzinga)
channels : Optional[str]
Channels of the news to retrieve. (provider: benzinga)
topics : Optional[str]
Topics of the news to retrieve. (provider: benzinga)
authors : Optional[str]
Authors of the news to retrieve. (provider: benzinga)
content_types : Optional[str]
Content types of the news to retrieve. (provider: benzinga)
offset : Optional[int]
Page offset, used in conjunction with limit. (provider: tiingo)
source : Optional[str]
A comma-separated list of the domains requested. (provider: tiingo)
Returns
-------
OBBject
results : List[WorldNews]
Serializable results.
provider : Optional[Literal['benzinga', 'fmp', 'intrinio', 'tiingo']]
Provider name.
warnings : Optional[List[Warning_]]
List of warnings.
chart : Optional[Chart]
Chart object.
extra : Dict[str, Any]
Extra info.
WorldNews
---------
date : datetime
The date of the data. The published date of the article.
title : str
Title of the article.
images : Optional[List[Dict[str, str]]]
Images associated with the article.
text : Optional[str]
Text/body of the article.
url : Optional[str]
URL to the article.
id : Optional[str]
Article ID. (provider: benzinga, intrinio)
author : Optional[str]
Author of the news. (provider: benzinga)
teaser : Optional[str]
Teaser of the news. (provider: benzinga)
channels : Optional[str]
Channels associated with the news. (provider: benzinga)
stocks : Optional[str]
Stocks associated with the news. (provider: benzinga)
tags : Optional[str]
Tags associated with the news. (provider: benzinga, tiingo)
updated : Optional[datetime]
Updated date of the news. (provider: benzinga)
site : Optional[str]
News source. (provider: fmp, tiingo)
company : Optional[Dict[str, Any]]
Company details related to the news article. (provider: intrinio)
symbols : Optional[str]
Ticker tagged in the fetched news. (provider: tiingo)
article_id : Optional[int]
Unique ID of the news article. (provider: tiingo)
crawl_date : Optional[datetime]
Date the news article was crawled. (provider: tiingo)
Examples
--------
>>> from openbb import obb
>>> obb.news.world(provider='fmp')
>>> obb.news.world(limit=100, provider='intrinio')
>>> # Get news on the specified dates.
>>> obb.news.world(start_date='2024-02-01', end_date='2024-02-07', provider='intrinio')
>>> # Display the headlines of the news.
>>> obb.news.world(display='headline', provider='benzinga')
>>> # Get news by topics.
>>> obb.news.world(topics='finance', provider='benzinga')
>>> # Get news by source using 'tingo' as provider.
>>> obb.news.world(provider='tiingo', source='bloomberg')
""" # noqa: E501
return self._run(
"/news/world",
**filter_inputs(
provider_choices={
"provider": self._get_provider(
provider,
"/news/world",
("benzinga", "fmp", "intrinio", "tiingo"),
)
},
standard_params={
"limit": limit,
"start_date": start_date,
"end_date": end_date,
},
extra_params=kwargs,
)
)