Skip to content

Commit

Permalink
CI listing quick fix (OpenBB-finance#6002)
Browse files Browse the repository at this point in the history
* BIGGGG LINTING

* fixing lints

* fixing lints

* black

* very ruff

* no export

* fix hedge_view again

* lints

* platform lints

* lints

* black

* black it @hjoaquim

* fix some more linting

---------

Co-authored-by: hjoaquim <[email protected]>
  • Loading branch information
2 people authored and luqmanbello committed Feb 1, 2024
1 parent 3c36b79 commit f43ff2a
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openbb_platform/core/openbb_core/app/model/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ class Preferences(BaseModel):
table_style: Literal["dark", "light"] = "dark"
request_timeout: PositiveInt = 15
metadata: bool = True
<<<<<<< HEAD
<<<<<<< HEAD
field_order: bool = (
False # Whether to display the field order by which the data was defined
)
=======
>>>>>>> 13283fbfce (CI listing quick fix (#6002))
=======
>>>>>>> 13283fbfce (CI listing quick fix (#6002))
output_type: Literal["OBBject", "dataframe", "polars", "numpy", "dict", "chart"] = (
Field(default="OBBject", description="Python default output type.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,16 @@ def build(path: str, ext_map: Optional[Dict[str, List[str]]] = None) -> str:
else None
),
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
examples=route.openapi_extra.get("examples", None),
=======
>>>>>>> 13283fbfce (CI listing quick fix (#6002))
=======
examples=route.openapi_extra.get("examples", None),
>>>>>>> c6eefd26b9 ([Feature] - Support for custom examples in router commands (#5993))
=======
>>>>>>> 13283fbfce (CI listing quick fix (#6002))
) # type: ignore
else:
doc += " /" if path else " /"
Expand Down
3 changes: 3 additions & 0 deletions openbb_platform/providers/oecd/openbb_oecd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"""OECD provider module."""
=======
"""FRED provider module."""
<<<<<<< HEAD
>>>>>>> 13283fbfce (CI listing quick fix (#6002))
=======
>>>>>>> 13283fbfce (CI listing quick fix (#6002))

from openbb_core.provider.abstract.provider import Provider
Expand Down
27 changes: 27 additions & 0 deletions openbb_platform/providers/ultima/openbb_ultima/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Ultima provider module."""

import warnings
from typing import Union

from openbb_core.provider.abstract.provider import Provider

ultima_provider: Union[Provider, None] = None

try:
from openbb_ultima.models.company_news import UltimaCompanyNewsFetcher
from openbb_ultima.models.sector_news import UltimaSectorNewsFetcher

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.""",
credentials=["api_key"],
fetcher_dict={
"CompanyNews": UltimaCompanyNewsFetcher,
"SectorNews": UltimaSectorNewsFetcher,
},
)
except ImportError:
warnings.warn(
"openbb-ultima is not installed. Please install openbb-ultima to use the Ultima provider."
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Ultima Company News Model."""

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

from openbb_core.provider.abstract.fetcher import Fetcher
from openbb_core.provider.standard_models.company_news import (
CompanyNewsData,
CompanyNewsQueryParams,
)
from openbb_ultima.utils.helpers import get_data
from pydantic import Field


class UltimaCompanyNewsQueryParams(CompanyNewsQueryParams):
"""Ultima Company News Query.
Source: https://api.ultimainsights.ai/v1/api-docs#/default/get_v1_getOpenBBProInsights__tickers_
"""

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


class UltimaCompanyNewsData(CompanyNewsData):
"""Ultima Company News Data."""

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

publisher: str = Field(description="Publisher of the news.")
risk_category: str = Field(description="Risk category of the news.")


class UltimaCompanyNewsFetcher(
Fetcher[
UltimaCompanyNewsQueryParams,
List[UltimaCompanyNewsData],
]
):
"""Transform the query, extract and transform the data from the Ultima endpoints."""

@staticmethod
def transform_query(params: Dict[str, Any]) -> UltimaCompanyNewsQueryParams:
"""Transform query."""
return UltimaCompanyNewsQueryParams(**params)

@staticmethod
def extract_data(
query: UltimaCompanyNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[Dict]:
"""Extract data from Ultima Insights API."""
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}"
response = get_data(url, **kwargs)
data.extend(response)

return data

@staticmethod
def transform_data(
query: UltimaCompanyNewsQueryParams,
data: List[Dict],
**kwargs: Any,
) -> List[UltimaCompanyNewsData]:
"""Transform data."""
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["symbols"] = 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"]
item["risk_category"] = item["riskCategory"]
results.append(UltimaCompanyNewsData.model_validate(item))
return results
103 changes: 103 additions & 0 deletions openbb_platform/providers/ultima/openbb_ultima/models/sector_news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
"""Ultima Sector News Model."""

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

from openbb_core.provider.abstract.fetcher import Fetcher
from openbb_core.provider.standard_models.sector_news import (
SectorNewsData,
SectorNewsQueryParams,
)
from openbb_ultima.utils.helpers import get_data
from pydantic import Field


class UltimaSectorNewsQueryParams(SectorNewsQueryParams):
"""Ultima Sector News Query.
Source: https://api.ultimainsights.ai/v1/api-docs#/default/get_v1_getOpenBBProInsights__tickers_
"""

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


class UltimaSectorNewsData(SectorNewsData):
"""Ultima Sector News Data."""

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

publisher: str = Field(description="Publisher of the news.")
risk_category: str = Field(description="Risk category of the news.")


class UltimaSectorNewsFetcher(
Fetcher[
UltimaSectorNewsQueryParams,
List[UltimaSectorNewsData],
]
):
"""Transform the query, extract and transform the data from the Ultima endpoints."""

@staticmethod
def transform_query(params: Dict[str, Any]) -> UltimaSectorNewsQueryParams:
"""Transform query."""
return UltimaSectorNewsQueryParams(**params)

@staticmethod
def extract_data(
query: UltimaSectorNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[Dict]:
"""Extract data from Ultima Insights API."""
token = credentials.get("ultima_api_key") if credentials else ""
kwargs["auth"] = token

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

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

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

querystring = ",".join(tickers)

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

return data

@staticmethod
def transform_data(
query: UltimaSectorNewsQueryParams,
data: List[Dict],
**kwargs: Any,
) -> List[UltimaSectorNewsData]:
"""Transform data."""
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["symbols"] = 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"]
item["risk_category"] = item["riskCategory"]
results.append(UltimaSectorNewsData.model_validate(item))
return results
26 changes: 26 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,26 @@
"""Ultima Helpers."""

from typing import Any, Dict

from openbb_core.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 auth is None or 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()

0 comments on commit f43ff2a

Please sign in to comment.