Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Intrinio EquityPriceHistorical - Return Error Message When Invalid Key #6357

Merged
merged 3 commits into from
May 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
DATA_DESCRIPTIONS,
QUERY_DESCRIPTIONS,
)
from openbb_core.provider.utils.errors import EmptyDataError
from openbb_core.provider.utils.helpers import (
ClientResponse,
ClientSession,
amake_requests,
amake_request,
get_querystring,
)
from pydantic import Field, PrivateAttr, model_validator
Expand Down Expand Up @@ -195,7 +196,6 @@ async def aextract_data(
) -> List[Dict]:
"""Return the raw data from the Intrinio endpoint."""
api_key = credentials.get("intrinio_api_key") if credentials else ""

base_url = f"https://api-v2.intrinio.com/securities/{query.symbol}/prices"
query_str = get_querystring(
query.model_dump(by_alias=True), ["symbol", "interval"]
Expand All @@ -211,6 +211,10 @@ async def aextract_data(
async def callback(response: ClientResponse, session: ClientSession) -> list:
"""Return the response."""
init_response = await response.json()
if "error" in init_response:
raise RuntimeError(
f"Intrinio Error Message -> {init_response['error']}: {init_response.get('message')}"
)

all_data: list = init_response.get(data_key, [])

Expand All @@ -226,7 +230,7 @@ async def callback(response: ClientResponse, session: ClientSession) -> list:

url = f"{base_url}&{query_str}&api_key={api_key}"

return await amake_requests([url], callback, **kwargs)
return await amake_request(url, response_callback=callback, **kwargs)

@staticmethod
def transform_data(
Expand All @@ -235,6 +239,8 @@ def transform_data(
**kwargs: Any,
) -> List[IntrinioEquityHistoricalData]:
"""Return the transformed data."""
if not data:
raise EmptyDataError("The request was returned empty.")
date_col = (
"time"
if query.interval in ["1m", "5m", "10m", "15m", "30m", "60m", "1h"]
Expand Down
Loading