Skip to content

Commit

Permalink
inegration complete
Browse files Browse the repository at this point in the history
  • Loading branch information
AdiSai committed Oct 31, 2023
1 parent 4564b52 commit 645976f
Show file tree
Hide file tree
Showing 13 changed files with 1,819 additions and 0 deletions.
1 change: 1 addition & 0 deletions openbb_platform/PROVIDERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
| [Polygon](./providers/polygon/README.md) | https://polygon.io/ | `openbb-polygon` | Free stock data APIs. Real time and historical data, unlimited usage, tick level and aggregate granularity, in standardized JSON and CSV formats. | [@OpenBB-Finance](https://github.com/OpenBB-finance) |
| [Benzinga](./providers/benzinga/README.md) | https://www.benzinga.com/ | `openbb-benzinga` | Stock Market Quotes, Business News, Financial News, Trading Ideas, and Stock Research by Professionals. | [@OpenBB-Finance](https://github.com/OpenBB-finance) |
| [FRED](./providers/fred/README.md) | https://fred.stlouisfed.org/ | `openbb-fred` | Download, graph, and track 823000 economic time series from 114 sources. | [@OpenBB-Finance](https://github.com/OpenBB-finance) |
| [Ultima](./providers/ultima/README.md) | https://ultimainsights.ai | `openbb-ultima` | Ultima Insights harnesses the power of LLMs + GPT to present relevant news to investors, often before it appears on platforms like Bloomberg. Ultima aims to provide timely and significant information for its users. | [@Ultima-Insights](https://github.com/Ultima-Insights)

<!-- Add your Data Provider integration above this line -->
15 changes: 15 additions & 0 deletions openbb_platform/providers/ultima/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# OpenBB Ultima Provider

This extension integrates the [Ultima Insights](https://www.ultimainsights.ai/) data provider into the OpenBB Platform.

## Installation

To install the extension:

```bash
pip install openbb-ultima
```

For development please check [Contribution Guidelines](https://github.com/OpenBB-finance/OpenBBTerminal/blob/feature/openbb-sdk-v4/openbb_platform/CONTRIBUTING.md).

Documentation available [here](https://docs.openbb.co/sdk).
Empty file.
13 changes: 13 additions & 0 deletions openbb_platform/providers/ultima/openbb_ultima/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Ultima provider module."""
from openbb_ultima.models.stock_news import UltimaStockNewsFetcher
from openbb_provider.abstract.provider import Provider

ultima_provider = Provider(
name="ultima",
website="https://www.ultimainsights.ai/openbb",
description="""Ultima harnesses the power of LLMs to deliver news before it hits the frontpage of Bloomberg.""",
required_credentials=["api_key"],
fetcher_dict={
"StockNews": UltimaStockNewsFetcher,
},
)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Ultima Stock News Fetcher."""


import math
from datetime import datetime
from typing import Any, Dict, List, Literal, Optional

from openbb_ultima.utils.helpers import get_data
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.standard_models.stock_news import (
StockNewsData,
StockNewsQueryParams,
)
from openbb_provider.utils.helpers import get_querystring
from pydantic import Field, field_validator

class UltimaStockNewsQueryParams(StockNewsQueryParams):
"""Ultima Stock News query.
Source: https://api.ultimainsights.ai/v1/api-docs#/default/get_v1_getOpenBBProInsights__tickers_
"""

__alias_dict__ = {
"symbols": "tickers",
}


class UltimaStockNewsData(StockNewsData):
"""Ultima Stock News Data."""

__alias_dict__ = {"date": "publishedDate", "text": "summary", "title": "headline"}

publisher: str = Field(description="Publisher of the news.")
ticker: str = Field(description="Ticker associated with the news.")
riskCategory: str = Field(description="Risk category of the news.")


class UltimaStockNewsFetcher(
Fetcher[
UltimaStockNewsQueryParams,
List[UltimaStockNewsData],
]
):
@staticmethod
def transform_query(params: Dict[str, Any]) -> UltimaStockNewsQueryParams:
return UltimaStockNewsQueryParams(**params)

@staticmethod
def extract_data(
query: UltimaStockNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> Dict:
token = credentials.get("ultima_api_key") if credentials else ""
kwargs["auth"] = token

base_url = "https://api.ultimainsights.ai/v1/getOpenBBProInsights"

querystring = str(query).split('=')[1].split("'")[1].replace(' ', '')

data = []
url = f"{base_url}/{querystring}"
print(url)
response = get_data(url, **kwargs)
data.extend(response)

return data

@staticmethod
def transform_data(
query: UltimaStockNewsQueryParams,
data: List[Dict],
**kwargs: Any,
) -> List[UltimaStockNewsData]:
results = []
for ele in data:
for key in ['8k_filings', 'articles', 'industry_summary']:
for item in ele[key]:
# manual assignment required for Pydantic to work
item['ticker'] = ele['ticker']
item['date'] = datetime.strptime(item['publishedDate'], '%Y-%m-%d %H:%M:%S')
item['title'] = item['headline']
item['url'] = item['url']
item['publisher'] = item['publisher']
results.append(UltimaStockNewsData.model_validate(item))
return results
Empty file.
24 changes: 24 additions & 0 deletions openbb_platform/providers/ultima/openbb_ultima/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Benzinga Helpers."""


from typing import Any, Dict

from openbb_provider import helpers


def get_data(url: str, **kwargs: Any) -> Dict:
"""Do an API request to Ultima and return the data."""
auth = kwargs.pop("auth", "")
if len(auth) == 0:
raise RuntimeError("Ultima API key is required.")
if "Bearer" not in auth:
auth = f"Bearer {auth}"
result = helpers.make_request(
url, timeout=10, headers={"accept": "application/json", "Authorization": auth}, **kwargs
)
if result.status_code != 200:
data = result.json()
message = data.get("message")
raise RuntimeError(f"Error in Ultima request -> {message}")

return result.json()
Loading

0 comments on commit 645976f

Please sign in to comment.