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

Custom request for all providers #5280

Merged
merged 9 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -110,14 +110,16 @@ def transform_query(params: Dict[str, Any]) -> BenzingaGlobalNewsQueryParams:

@staticmethod
def extract_data(
query: BenzingaGlobalNewsQueryParams, credentials: Optional[Dict[str, str]]
query: BenzingaGlobalNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[BenzingaGlobalNewsData]:
api_key = credentials.get("benzinga_api_key") if credentials else ""

base_url = "https://api.benzinga.com/api/v2/news"
querystring = get_querystring(query.dict(by_alias=True), [])
request_url = f"{base_url}?{querystring}&token={api_key}"
data = get_data(request_url)
data = get_data(request_url, **kwargs)

if len(data) == 0:
raise RuntimeError("No news found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ def transform_query(params: Dict[str, Any]) -> BenzingaStockNewsQueryParams:

@staticmethod
def extract_data(
query: BenzingaStockNewsQueryParams, credentials: Optional[Dict[str, str]]
query: BenzingaStockNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[BenzingaStockNewsData]:
api_key = credentials.get("benzinga_api_key") if credentials else ""

base_url = "https://api.benzinga.com/api/v2/news"
querystring = get_querystring(query.dict(by_alias=True), [])
request_url = f"{base_url}?{querystring}&token={api_key}"
data = get_data(request_url)
data = get_data(request_url, **kwargs)

if len(data) == 0:
raise RuntimeError("No news found")
Expand Down
10 changes: 7 additions & 3 deletions openbb_sdk/providers/benzinga/openbb_benzinga/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
"""Benzinga Helpers."""


import requests
from typing import Any

from openbb_provider import helpers
from pydantic import BaseModel


def get_data(url: str) -> dict:
r = requests.get(url, timeout=10, headers={"accept": "application/json"})
def get_data(url: str, **kwargs: Any) -> dict:
r = helpers.make_request(
url, timeout=10, headers={"accept": "application/json"}, **kwargs
)
if r.status_code != 200:
data = r.json()
if data == ['Access denied for user 0 "anonymous"']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def transform_query(params: Dict[str, Any]) -> FMPAnalystEstimatesQueryParams:

@staticmethod
def extract_data(
query: FMPAnalystEstimatesQueryParams, credentials: Optional[Dict[str, str]]
query: FMPAnalystEstimatesQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPAnalystEstimatesData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -70,7 +72,7 @@ def extract_data(
url = create_url(
3, f"analyst-estimates/{query.symbol}", api_key, query, ["symbol"]
)
return get_data_many(url, FMPAnalystEstimatesData)
return get_data_many(url, FMPAnalystEstimatesData, **kwargs)

@staticmethod
def transform_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ def transform_query(params: Dict[str, Any]) -> FMPAvailableIndicesQueryParams:

@staticmethod
def extract_data(
query: FMPAvailableIndicesQueryParams, credentials: Optional[Dict[str, str]]
query: FMPAvailableIndicesQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPAvailableIndicesData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

base_url = "https://financialmodelingprep.com/api/v3"
url = f"{base_url}/symbol/available-indexes?apikey={api_key}"
return get_data_many(url, FMPAvailableIndicesData)
return get_data_many(url, FMPAvailableIndicesData, **kwargs)

@staticmethod
def transform_data(
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/balance_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ def transform_query(params: Dict[str, Any]) -> FMPBalanceSheetQueryParams:

@staticmethod
def extract_data(
query: FMPBalanceSheetQueryParams, credentials: Optional[Dict[str, str]]
query: FMPBalanceSheetQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPBalanceSheetData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(
3, f"balance-sheet-statement/{query.symbol}", api_key, query, ["symbol"]
)
return get_data_many(url, FMPBalanceSheetData)
return get_data_many(url, FMPBalanceSheetData, **kwargs)

@staticmethod
def transform_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def transform_query(params: Dict[str, Any]) -> FMPBalanceSheetGrowthQueryParams:
def extract_data(
query: FMPBalanceSheetGrowthQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPBalanceSheetGrowthData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -98,7 +99,7 @@ def extract_data(
query,
["symbol"],
)
return get_data_many(url, FMPBalanceSheetGrowthData)
return get_data_many(url, FMPBalanceSheetGrowthData, **kwargs)

@staticmethod
def transform_data(
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/cash_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def transform_query(params: Dict[str, Any]) -> FMPCashFlowStatementQueryParams:

@staticmethod
def extract_data(
query: FMPCashFlowStatementQueryParams, credentials: Optional[Dict[str, str]]
query: FMPCashFlowStatementQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPCashFlowStatementData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -97,7 +99,7 @@ def extract_data(
url = create_url(
3, f"cash-flow-statement/{query.symbol}", api_key, query, ["symbol"]
)
return get_data_many(url, FMPCashFlowStatementData)
return get_data_many(url, FMPCashFlowStatementData, **kwargs)

@staticmethod
def transform_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ def transform_query(
def extract_data(
query: FMPCashFlowStatementGrowthQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPCashFlowStatementGrowthData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(
3, f"cash-flow-statement-growth/{query.symbol}", api_key, query, ["symbol"]
)
return get_data_many(url, FMPCashFlowStatementGrowthData)
return get_data_many(url, FMPCashFlowStatementGrowthData, **kwargs)

@staticmethod
def transform_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ def transform_query(params: Dict[str, Any]) -> FMPCompanyOverviewQueryParams:

@staticmethod
def extract_data(
query: FMPCompanyOverviewQueryParams, credentials: Optional[Dict[str, str]]
query: FMPCompanyOverviewQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPCompanyOverviewData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

base_url = "https://financialmodelingprep.com/api/v3/"
request_url = f"{base_url}profile/{query.symbol}?apikey={api_key}"
data = get_data(request_url)
data = get_data(request_url, **kwargs)
if isinstance(data, dict):
raise ValueError("Expected list of dicts, got dict")

Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/crypto_eod.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def transform_query(params: Dict[str, Any]) -> FMPCryptoEODQueryParams:

@staticmethod
def extract_data(
query: FMPCryptoEODQueryParams, credentials: Optional[Dict[str, str]]
query: FMPCryptoEODQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPCryptoEODData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -80,7 +82,7 @@ def extract_data(
query_str = query_str.replace("start_date", "from").replace("end_date", "to")
url = f"{base_url}historical-price-full/crypto/{query.symbol}?{query_str}&apikey={api_key}"

return get_data_many(url, FMPCryptoEODData, "historical")
return get_data_many(url, FMPCryptoEODData, "historical", **kwargs)

@staticmethod
def transform_data(data: List[FMPCryptoEODData]) -> List[FMPCryptoEODData]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ def transform_query(params: Dict[str, Any]) -> FMPDividendCalendarQueryParams:

@staticmethod
def extract_data(
query: FMPDividendCalendarQueryParams, credentials: Optional[Dict[str, str]]
query: FMPDividendCalendarQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPDividendCalendarData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

base_url = "https://financialmodelingprep.com/api/v3"
query_str = get_querystring(query.dict(by_alias=True), [])
query_str = query_str.replace("start_date", "from").replace("end_date", "to")
url = f"{base_url}/stock_dividend_calendar?{query_str}&apikey={api_key}"
return get_data_many(url, FMPDividendCalendarData)
return get_data_many(url, FMPDividendCalendarData, **kwargs)

@staticmethod
def transform_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ def transform_query(params: Dict[str, Any]) -> FMPEarningsCalendarQueryParams:

@staticmethod
def extract_data(
query: FMPEarningsCalendarQueryParams, credentials: Optional[Dict[str, str]]
query: FMPEarningsCalendarQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPEarningsCalendarData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(
3, f"historical/earning_calendar/{query.symbol}", api_key, query, ["symbol"]
)
return get_data_many(url, FMPEarningsCalendarData)
return get_data_many(url, FMPEarningsCalendarData, **kwargs)

@staticmethod
def transform_data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def transform_query(params: Dict[str, Any]) -> FMPEarningsCallTranscriptQueryPar
def extract_data(
query: FMPEarningsCallTranscriptQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPEarningsCallTranscriptData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -60,7 +61,7 @@ def extract_data(
query,
["symbol"],
)
return get_data_many(url, FMPEarningsCallTranscriptData)
return get_data_many(url, FMPEarningsCallTranscriptData, **kwargs)

@staticmethod
def transform_data(
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/esg_risk_rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ def transform_query(params: Dict[str, Any]) -> FMPESGRiskRatingQueryParams:

@staticmethod
def extract_data(
query: FMPESGRiskRatingQueryParams, credentials: Optional[Dict[str, str]]
query: FMPESGRiskRatingQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any
) -> List[FMPESGRiskRatingData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(
4, "esg-environmental-social-governance-data-ratings", api_key, query
)
return get_data_many(url, FMPESGRiskRatingData)
return get_data_many(url, FMPESGRiskRatingData, **kwargs)

@staticmethod
def transform_data(data: List[FMPESGRiskRatingData]) -> List[FMPESGRiskRatingData]:
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/esg_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ def transform_query(params: Dict[str, Any]) -> FMPESGScoreQueryParams:

@staticmethod
def extract_data(
query: FMPESGScoreQueryParams, credentials: Optional[Dict[str, str]]
query: FMPESGScoreQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any
) -> List[FMPESGScoreData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(4, "esg-environmental-social-governance-data", api_key, query)
return get_data_many(url, FMPESGScoreData)
return get_data_many(url, FMPESGScoreData, **kwargs)

@staticmethod
def transform_data(data: List[FMPESGScoreData]) -> List[FMPESGScoreData]:
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/esg_sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ def transform_query(params: Dict[str, Any]) -> FMPESGSectorQueryParams:

@staticmethod
def extract_data(
query: FMPESGSectorQueryParams, credentials: Optional[Dict[str, str]]
query: FMPESGSectorQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any
) -> List[FMPESGSectorData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(
4, "esg-environmental-social-governance-sector-benchmark", api_key, query
)
return get_data_many(url, FMPESGSectorData)
return get_data_many(url, FMPESGSectorData, **kwargs)

@staticmethod
def transform_data(data: List[FMPESGSectorData]) -> List[FMPESGSectorData]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ def transform_query(params: Dict[str, Any]) -> FMPExecutiveCompensationQueryPara
def extract_data(
query: FMPExecutiveCompensationQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPExecutiveCompensationData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(4, "governance/executive_compensation", api_key, query)
return get_data_many(url, FMPExecutiveCompensationData)
return get_data_many(url, FMPExecutiveCompensationData, **kwargs)

@staticmethod
def transform_data(
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/forex_eod.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def transform_query(params: Dict[str, Any]) -> FMPForexEODQueryParams:

@staticmethod
def extract_data(
query: FMPForexEODQueryParams, credentials: Optional[Dict[str, str]]
query: FMPForexEODQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPForexEODData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -75,7 +77,7 @@ def extract_data(
query_str = query_str.replace("start_date", "from").replace("end_date", "to")
url = f"{base_url}/historical-price-full/forex/{query.symbol}?{query_str}&apikey={api_key}"

return get_data_many(url, FMPForexEODData, "historical")
return get_data_many(url, FMPForexEODData, "historical", **kwargs)

@staticmethod
def transform_data(data: List[FMPForexEODData]) -> List[FMPForexEODData]:
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/forex_pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ def transform_query(params: Dict[str, Any]) -> FMPForexPairsQueryParams:

@staticmethod
def extract_data(
query: FMPForexPairsQueryParams, credentials: Optional[Dict[str, str]]
query: FMPForexPairsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> List[FMPForexPairsData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

base_url = "https://financialmodelingprep.com/api/v3"
url = f"{base_url}/symbol/available-forex-currency-pairs?apikey={api_key}"

return get_data_many(url, FMPForexPairsData)
return get_data_many(url, FMPForexPairsData, **kwargs)

@staticmethod
def transform_data(data: List[FMPForexPairsData]) -> List[FMPForexPairsData]:
Expand Down
6 changes: 4 additions & 2 deletions openbb_sdk/providers/fmp/openbb_fmp/models/global_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ def transform_query(params: Dict[str, Any]) -> FMPGlobalNewsQueryParams:

@staticmethod
def extract_data(
query: FMPGlobalNewsQueryParams, credentials: Optional[Dict[str, str]]
query: FMPGlobalNewsQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any
) -> List[FMPGlobalNewsData]:
api_key = credentials.get("fmp_api_key") if credentials else ""

url = create_url(4, "general_news", api_key, query)
return get_data_many(url, FMPGlobalNewsData)
return get_data_many(url, FMPGlobalNewsData, **kwargs)

@staticmethod
def transform_data(data: List[FMPGlobalNewsData]) -> List[FMPGlobalNewsData]:
Expand Down
Loading