{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How The OpenBB Platform Works" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from openbb import obb" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "obb" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "/news\n", " company\n", " world\n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "obb.news" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method world in module openbb.package.news:\n", "\n", "world(limit: Annotated[int, OpenBBField(description='The number of data entries to return. The number of articles to return.')] = 2500, start_date: Annotated[Union[datetime.date, NoneType, str], OpenBBField(description='Start date of the data, in YYYY-MM-DD format.')] = None, end_date: Annotated[Union[datetime.date, NoneType, str], OpenBBField(description='End date of the data, in YYYY-MM-DD format.')] = None, provider: Annotated[Optional[Literal['benzinga', 'biztoc', 'fmp', 'intrinio', 'tiingo']], OpenBBField(description='The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: benzinga, biztoc, fmp, intrinio, tiingo.')] = None, **kwargs) -> openbb_core.app.model.obbject.OBBject method of openbb.package.news.ROUTER_news instance\n", " World News. Global news data.\n", "\n", " Parameters\n", " ----------\n", " limit : int\n", " The number of data entries to return. The number of articles to return.\n", " start_date : Union[date, None, str]\n", " Start date of the data, in YYYY-MM-DD format.\n", " end_date : Union[date, None, str]\n", " End date of the data, in YYYY-MM-DD format.\n", " provider : Optional[Literal['benzinga', 'biztoc', 'fmp', 'intrinio', 'tiingo']]\n", " The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: benzinga, biztoc, fmp, intrinio, tiingo.\n", " date : Optional[datetime.date]\n", " A specific date to get data for. (provider: benzinga)\n", " display : Literal['headline', 'abstract', 'full']\n", " Specify headline only (headline), headline + teaser (abstract), or headline + full body (full). (provider: benzinga)\n", " updated_since : Optional[int]\n", " Number of seconds since the news was updated. (provider: benzinga)\n", " published_since : Optional[int]\n", " Number of seconds since the news was published. (provider: benzinga)\n", " sort : Literal['id', 'created', 'updated']\n", " Key to sort the news by. (provider: benzinga)\n", " order : Literal['asc', 'desc']\n", " Order to sort the news by. (provider: benzinga)\n", " isin : Optional[str]\n", " The ISIN of the news to retrieve. (provider: benzinga)\n", " cusip : Optional[str]\n", " The CUSIP of the news to retrieve. (provider: benzinga)\n", " channels : Optional[str]\n", " Channels of the news to retrieve. (provider: benzinga)\n", " topics : Optional[str]\n", " Topics of the news to retrieve. (provider: benzinga)\n", " authors : Optional[str]\n", " Authors of the news to retrieve. (provider: benzinga)\n", " content_types : Optional[str]\n", " Content types of the news to retrieve. (provider: benzinga)\n", " term : Optional[str]\n", " Search term to filter articles by. This overrides all other filters. (provider: biztoc)\n", " source : Optional[Union[str, Literal['yahoo', 'moody', 'moody_us_news', 'moody_us_press_releases']]]\n", " Filter by a specific publisher. Only valid when filter is set to source. (provider: biztoc);\n", " The source of the news article. (provider: intrinio);\n", " A comma-separated list of the domains requested. (provider: tiingo)\n", " sentiment : Optional[Literal['positive', 'neutral', 'negative']]\n", " Return news only from this source. (provider: intrinio)\n", " language : Optional[str]\n", " Filter by language. Unsupported for yahoo source. (provider: intrinio)\n", " topic : Optional[str]\n", " Filter by topic. Unsupported for yahoo source. (provider: intrinio)\n", " word_count_greater_than : Optional[int]\n", " News stories will have a word count greater than this value. Unsupported for yahoo source. (provider: intrinio)\n", " word_count_less_than : Optional[int]\n", " News stories will have a word count less than this value. Unsupported for yahoo source. (provider: intrinio)\n", " is_spam : Optional[bool]\n", " Filter whether it is marked as spam or not. Unsupported for yahoo source. (provider: intrinio)\n", " business_relevance_greater_than : Optional[float]\n", " News stories will have a business relevance score more than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1. (provider: intrinio)\n", " business_relevance_less_than : Optional[float]\n", " News stories will have a business relevance score less than this value. Unsupported for yahoo source. Value is a decimal between 0 and 1. (provider: intrinio)\n", " offset : Optional[int]\n", " Page offset, used in conjunction with limit. (provider: tiingo)\n", "\n", " Returns\n", " -------\n", " OBBject\n", " results : List[WorldNews]\n", " Serializable results.\n", " provider : Optional[Literal['benzinga', 'biztoc', 'fmp', 'intrinio', 'tiingo']]\n", " Provider name.\n", " warnings : Optional[List[Warning_]]\n", " List of warnings.\n", " chart : Optional[Chart]\n", " Chart object.\n", " extra : Dict[str, Any]\n", " Extra info.\n", "\n", " WorldNews\n", " ---------\n", " date : datetime\n", " The date of the data. The published date of the article.\n", " title : str\n", " Title of the article.\n", " images : Optional[List[Dict[str, str]]]\n", " Images associated with the article.\n", " text : Optional[str]\n", " Text/body of the article.\n", " url : Optional[str]\n", " URL to the article.\n", " id : Optional[str]\n", " Article ID. (provider: benzinga, intrinio)\n", " author : Optional[str]\n", " Author of the news. (provider: benzinga)\n", " teaser : Optional[str]\n", " Teaser of the news. (provider: benzinga)\n", " channels : Optional[str]\n", " Channels associated with the news. (provider: benzinga)\n", " stocks : Optional[str]\n", " Stocks associated with the news. (provider: benzinga)\n", " tags : Optional[Union[str, List[str]]]\n", " Tags associated with the news. (provider: benzinga, biztoc, tiingo)\n", " updated : Optional[datetime]\n", " Updated date of the news. (provider: benzinga)\n", " score : Optional[float]\n", " Search relevance score for the article. (provider: biztoc)\n", " site : Optional[str]\n", " News source. (provider: fmp, tiingo)\n", " source : Optional[str]\n", " The source of the news article. (provider: intrinio)\n", " summary : Optional[str]\n", " The summary of the news article. (provider: intrinio)\n", " topics : Optional[str]\n", " The topics related to the news article. (provider: intrinio)\n", " word_count : Optional[int]\n", " The word count of the news article. (provider: intrinio)\n", " business_relevance : Optional[float]\n", " How strongly correlated the news article is to the business (provider: intrinio)\n", " sentiment : Optional[str]\n", " The sentiment of the news article - i.e, negative, positive. (provider: intrinio)\n", " sentiment_confidence : Optional[float]\n", " The confidence score of the sentiment rating. (provider: intrinio)\n", " language : Optional[str]\n", " The language of the news article. (provider: intrinio)\n", " spam : Optional[bool]\n", " Whether the news article is spam. (provider: intrinio)\n", " copyright : Optional[str]\n", " The copyright notice of the news article. (provider: intrinio)\n", " company : Optional[IntrinioCompany]\n", " The Intrinio Company object. Contains details company reference data. (provider: intrinio)\n", " security : Optional[IntrinioSecurity]\n", " The Intrinio Security object. Contains the security details related to the news article. (provider: intrinio)\n", " symbols : Optional[str]\n", " Ticker tagged in the fetched news. (provider: tiingo)\n", " article_id : Optional[int]\n", " Unique ID of the news article. (provider: tiingo)\n", " crawl_date : Optional[datetime]\n", " Date the news article was crawled. (provider: tiingo)\n", "\n", " Examples\n", " --------\n", " >>> from openbb import obb\n", " >>> obb.news.world(provider='fmp')\n", " >>> obb.news.world(limit=100, provider='intrinio')\n", " >>> # Get news on the specified dates.\n", " >>> obb.news.world(start_date='2024-02-01', end_date='2024-02-07', provider='intrinio')\n", " >>> # Display the headlines of the news.\n", " >>> obb.news.world(display='headline', provider='benzinga')\n", " >>> # Get news by topics.\n", " >>> obb.news.world(topics='finance', provider='benzinga')\n", " >>> # Get news by source using 'tingo' as provider.\n", " >>> obb.news.world(provider='tiingo', source='bloomberg')\n", " >>> # Filter aticles by term using 'biztoc' as provider.\n", " >>> obb.news.world(provider='biztoc', term='apple')\n", "\n" ] } ], "source": [ "help(obb.news.world)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Uniform interface allows switching between providers" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| date | \n", "2024-08-22 18:02:00+00:00 | \n", "
|---|---|
| title | \n", "Natural Grocers® Teams Up With Local Artist, S... | \n", "
| text | \n", "Natural Grocers®, the leading family-operated ... | \n", "
| url | \n", "https://finance.yahoo.com/news/natural-grocers... | \n", "
| source | \n", "yahoo | \n", "
| id | \n", "new_DDGR2v | \n", "
| company | \n", "{'id': 'com_g4Q8NX', 'ticker': 'NGVC', 'name':... | \n", "
| date | \n", "2024-08-22 14:46:33-04:00 | \n", "
|---|---|
| title | \n", "Behind the Scenes of Vertiv Hldgs's Latest Opt... | \n", "
| images | \n", "[{'size': 'thumb', 'url': 'https://cdn.benzing... | \n", "
| text | \n", "<p>Whales with a lot of money to spend have ta... | \n", "
| url | \n", "https://www.benzinga.com/insights/options/24/0... | \n", "
| id | \n", "40515079 | \n", "
| author | \n", "Benzinga Insights | \n", "
| teaser | \n", "\n", " |
| channels | \n", "Options,Markets | \n", "
| stocks | \n", "VRT | \n", "
| tags | \n", "BZI-UOA | \n", "
| updated | \n", "2024-08-22 14:46:33-04:00 | \n", "
Whales with a lot of money to spend have ta...\n",
"url https://www.benzinga.com/insights/options/24/0...\n",
"id 40515079\n",
"author Benzinga Insights\n",
"teaser \n",
"channels Options,Markets\n",
"stocks VRT\n",
"tags BZI-UOA\n",
"updated 2024-08-22 14:46:33-04:00"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"obb.news.world(limit=1, provider=\"benzinga\").to_df().T"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"\n",
"---\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Standardization of input and output schemas is done with Pydantic models"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### This is a standard model"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'date': FieldInfo(annotation=datetime, required=True, alias_priority=1, validation_alias='date', serialization_alias='date', description='The date of the data. The published date of the article.'),\n",
" 'title': FieldInfo(annotation=str, required=True, alias_priority=1, validation_alias='title', serialization_alias='title', description='Title of the article.'),\n",
" 'images': FieldInfo(annotation=Union[List[Dict[str, str]], NoneType], required=False, default=None, alias_priority=1, validation_alias='images', serialization_alias='images', description='Images associated with the article.'),\n",
" 'text': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='text', serialization_alias='text', description='Text/body of the article.'),\n",
" 'url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='url', serialization_alias='url', description='URL to the article.')}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from openbb_core.provider.standard_models.world_news import WorldNewsData\n",
"\n",
"WorldNewsData.__fields__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### These are provider models"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from openbb_intrinio.models.world_news import IntrinioWorldNewsData\n",
"from openbb_benzinga.models.world_news import BenzingaWorldNewsData"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'date': FieldInfo(annotation=datetime, required=True, alias_priority=1, validation_alias='date', serialization_alias='date', description='The date of the data. The published date of the article.'),\n",
" 'title': FieldInfo(annotation=str, required=True, alias_priority=1, validation_alias='title', serialization_alias='title', description='Title of the article.'),\n",
" 'images': FieldInfo(annotation=Union[List[Dict[str, str]], NoneType], required=False, default=None, alias_priority=1, validation_alias='images', serialization_alias='images', description='Images associated with the article.'),\n",
" 'text': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='text', serialization_alias='text', description='Text/body of the article.'),\n",
" 'url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='url', serialization_alias='url', description='URL to the article.'),\n",
" 'source': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='source', serialization_alias='source', description='The source of the news article.'),\n",
" 'summary': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='summary', serialization_alias='summary', description='The summary of the news article.'),\n",
" 'topics': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='topics', serialization_alias='topics', description='The topics related to the news article.'),\n",
" 'word_count': FieldInfo(annotation=Union[int, NoneType], required=False, default=None, alias_priority=1, validation_alias='wordCount', serialization_alias='word_count', description='The word count of the news article.'),\n",
" 'business_relevance': FieldInfo(annotation=Union[float, NoneType], required=False, default=None, alias_priority=1, validation_alias='businessRelevance', serialization_alias='business_relevance', description=' \\tHow strongly correlated the news article is to the business'),\n",
" 'sentiment': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='sentiment', serialization_alias='sentiment', description='The sentiment of the news article - i.e, negative, positive.'),\n",
" 'sentiment_confidence': FieldInfo(annotation=Union[float, NoneType], required=False, default=None, alias_priority=1, validation_alias='sentimentConfidence', serialization_alias='sentiment_confidence', description='The confidence score of the sentiment rating.'),\n",
" 'language': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='language', serialization_alias='language', description='The language of the news article.'),\n",
" 'spam': FieldInfo(annotation=Union[bool, NoneType], required=False, default=None, alias_priority=1, validation_alias='spam', serialization_alias='spam', description='Whether the news article is spam.'),\n",
" 'copyright': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='copyright', serialization_alias='copyright', description='The copyright notice of the news article.'),\n",
" 'id': FieldInfo(annotation=str, required=True, alias_priority=1, validation_alias='id', serialization_alias='id', description='Article ID.'),\n",
" 'company': FieldInfo(annotation=Union[IntrinioCompany, NoneType], required=False, default=None, alias_priority=1, validation_alias='company', serialization_alias='company', description='The Intrinio Company object. Contains details company reference data.'),\n",
" 'security': FieldInfo(annotation=Union[IntrinioSecurity, NoneType], required=False, default=None, alias_priority=1, validation_alias='security', serialization_alias='security', description='The Intrinio Security object. Contains the security details related to the news article.')}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"IntrinioWorldNewsData.__fields__"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'date': FieldInfo(annotation=datetime, required=True, alias_priority=1, validation_alias='date', serialization_alias='date', description='The date of the data. The published date of the article.'),\n",
" 'title': FieldInfo(annotation=str, required=True, alias_priority=1, validation_alias='title', serialization_alias='title', description='Title of the article.'),\n",
" 'images': FieldInfo(annotation=Union[List[Dict[str, str]], NoneType], required=False, default=None, alias_priority=1, validation_alias='images', serialization_alias='images', description='Images associated with the article.'),\n",
" 'text': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='text', serialization_alias='text', description='Text/body of the article.'),\n",
" 'url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='url', serialization_alias='url', description='URL to the article.'),\n",
" 'id': FieldInfo(annotation=str, required=True, alias_priority=1, validation_alias='id', serialization_alias='id', description='Article ID.'),\n",
" 'author': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='author', serialization_alias='author', description='Author of the news.'),\n",
" 'teaser': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='teaser', serialization_alias='teaser', description='Teaser of the news.'),\n",
" 'channels': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='channels', serialization_alias='channels', description='Channels associated with the news.'),\n",
" 'stocks': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='stocks', serialization_alias='stocks', description='Stocks associated with the news.'),\n",
" 'tags': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, alias_priority=1, validation_alias='tags', serialization_alias='tags', description='Tags associated with the news.'),\n",
" 'updated': FieldInfo(annotation=Union[datetime, NoneType], required=False, default=None, alias_priority=1, validation_alias='updated', serialization_alias='updated', description='Updated date of the news.')}"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"BenzingaWorldNewsData.__fields__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Inheritance, field mapping and quality assurance"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Provider models inherit from Standard Models"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"issubclass(BenzingaWorldNewsData, WorldNewsData)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Provider models use aliases to map to standard fields"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'date': 'created', 'text': 'body', 'images': 'image'}"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"BenzingaWorldNewsData.__alias_dict__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Provider models implement field validation"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'date_validate': Decorator(cls_ref='openbb_intrinio.models.world_news.IntrinioWorldNewsData:140298041431344', cls_var_name='date_validate', func=