replace fetcher list by fetcher dict and black

This commit is contained in:
Diogo Sousa
2023-07-29 03:14:18 +01:00
parent 58589c924f
commit d02b053198
10 changed files with 67 additions and 69 deletions

View File

@@ -13,5 +13,8 @@ benzinga_provider = Provider(
name="benzinga",
description="Provider for Benzinga.",
required_credentials=["api_key"],
fetcher_list=[BenzingaGlobalNewsFetcher, BenzingaStockNewsFetcher],
fetcher_dict={
"GlobalNews": BenzingaGlobalNewsFetcher,
"StockNews": BenzingaStockNewsFetcher,
},
)

View File

@@ -1,7 +1,6 @@
"""Benzinga Helpers."""
import requests
from pydantic import BaseModel

View File

@@ -52,46 +52,46 @@ fmp_provider = Provider(
name="fmp",
description="Provider for FMP.",
required_credentials=["api_key"],
fetcher_list=[
FMPKeyExecutivesFetcher,
FMPStockEODFetcher,
FMPGlobalNewsFetcher,
FMPStockNewsFetcher,
FMPIncomeStatementFetcher,
FMPBalanceSheetFetcher,
FMPCashFlowStatementFetcher,
FMPShareStatisticsFetcher,
FMPMajorIndicesEODFetcher,
FMPRevenueGeographicFetcher,
FMPRevenueBusinessLineFetcher,
FMPInstitutionalOwnershipFetcher,
FMPCompanyOverviewFetcher,
FMPStockInsiderTradingFetcher,
FMPStockOwnershipFetcher,
FMPESGScoreFetcher,
FMPESGSectorFetcher,
FMPESGRiskRatingFetcher,
FMPPriceTargetConsensusFetcher,
FMPPriceTargetFetcher,
FMPAnalystEstimatesFetcher,
FMPEarningsCalendarFetcher,
FMPEarningsCallTranscriptFetcher,
FMPHistoricalStockSplitsFetcher,
FMPStockSplitCalendarFetcher,
FMPHistoricalDividendsFetcher,
FMPKeyMetricsFetcher,
FMPSECFilingsFetcher,
FMPTreasuryRatesFetcher,
FMPExecutiveCompensationFetcher,
FMPCryptoEODFetcher,
FMPForexEODFetcher,
FMPForexPairsFetcher,
FMPStockPeersFetcher,
FMPStockMultiplesFetcher,
FMPHistoricalEmployeesFetcher,
FMPAvailableIndicesFetcher,
FMPRiskPremiumFetcher,
FMPMajorIndicesConstituentsFetcher,
FMPDividendCalendarFetcher,
],
fetcher_dict={
"KeyExecutives": FMPKeyExecutivesFetcher,
"StockEOD,": FMPStockEODFetcher,
"GlobalNews": FMPGlobalNewsFetcher,
"StockNews": FMPStockNewsFetcher,
"IncomeStatement": FMPIncomeStatementFetcher,
"BalanceSheet": FMPBalanceSheetFetcher,
"CashFlowStatement": FMPCashFlowStatementFetcher,
"ShareStatistics": FMPShareStatisticsFetcher,
"MajorIndicesEOD": FMPMajorIndicesEODFetcher,
"RevenueGeographic": FMPRevenueGeographicFetcher,
"RevenueBusinessLine": FMPRevenueBusinessLineFetcher,
"InstitutionalOwnership": FMPInstitutionalOwnershipFetcher,
"CompanyOverview": FMPCompanyOverviewFetcher,
"StockInsiderTrading": FMPStockInsiderTradingFetcher,
"StockOwnership": FMPStockOwnershipFetcher,
"ESGScore,": FMPESGScoreFetcher,
"ESGSector": FMPESGSectorFetcher,
"ESGRiskRating": FMPESGRiskRatingFetcher,
"PriceTargetConsensus": FMPPriceTargetConsensusFetcher,
"PriceTarget": FMPPriceTargetFetcher,
"AnalystEstimates": FMPAnalystEstimatesFetcher,
"EarningsCalendar": FMPEarningsCalendarFetcher,
"EarningsCallTranscript": FMPEarningsCallTranscriptFetcher,
"HistoricalStockSplits": FMPHistoricalStockSplitsFetcher,
"StockSplitCalendar": FMPStockSplitCalendarFetcher,
"HistoricalDividends": FMPHistoricalDividendsFetcher,
"KeyMetrics": FMPKeyMetricsFetcher,
"SECFilings": FMPSECFilingsFetcher,
"TreasuryRates": FMPTreasuryRatesFetcher,
"ExecutiveCompensation": FMPExecutiveCompensationFetcher,
"CryptoEOD": FMPCryptoEODFetcher,
"ForexEOD,": FMPForexEODFetcher,
"ForexPairs": FMPForexPairsFetcher,
"StockPeers": FMPStockPeersFetcher,
"StockMultiples": FMPStockMultiplesFetcher,
"HistoricalEmployees": FMPHistoricalEmployeesFetcher,
"AvailableIndices": FMPAvailableIndicesFetcher,
"RiskPremium": FMPRiskPremiumFetcher,
"MajorIndicesConstituents": FMPMajorIndicesConstituentsFetcher,
"DividendCalendar": FMPDividendCalendarFetcher,
},
)

View File

@@ -11,5 +11,5 @@ fred_provider = Provider(
name="fred",
description="Provider for FRED.",
required_credentials=["api_key"],
fetcher_list=[FREDCPIFetcher],
fetcher_dict={"CPI": FREDCPIFetcher},
)

View File

@@ -18,15 +18,15 @@ polygon_provider = Provider(
name="polygon",
description="Provider for Polygon.",
required_credentials=["api_key"],
fetcher_list=[
PolygonStockEODFetcher,
PolygonStockNewsFetcher,
PolygonBalanceSheetFetcher,
PolygonIncomeStatementFetcher,
PolygonCashFlowStatementFetcher,
PolygonCryptoEODFetcher,
PolygonMajorIndicesEODFetcher,
PolygonForexEODFetcher,
PolygonForexPairsFetcher,
],
fetcher_dict={
"StockEOD": PolygonStockEODFetcher,
"StockNews": PolygonStockNewsFetcher,
"BalanceSheet": PolygonBalanceSheetFetcher,
"IncomeStatement": PolygonIncomeStatementFetcher,
"CashFlowStatement": PolygonCashFlowStatementFetcher,
"CryptoEOD": PolygonCryptoEODFetcher,
"MajorIndicesEOD": PolygonMajorIndicesEODFetcher,
"ForexEOD": PolygonForexEODFetcher,
"ForexPairs": PolygonForexPairsFetcher,
},
)

View File

@@ -171,10 +171,10 @@ class ProviderInterface:
field: ModelField,
provider_name: Optional[str] = None,
query: bool = False,
force_optional: bool = False
force_optional: bool = False,
) -> DataclassField:
new_name = name.replace(".", "_")
type_ = field.outer_type_ # field.type_ don't work for nested types
type_ = field.outer_type_ # field.type_ don't work for nested types
description = field.field_info.description
if field.required:
@@ -186,8 +186,6 @@ class ProviderInterface:
else:
default = field.default
if query:
# We need to use query if we want the field description to show up in the
# swagger, it's a fastapi limitation
@@ -269,7 +267,9 @@ class ProviderInterface:
else:
for name, field in model_details["Data"]["fields"].items():
if name not in providers["openbb"]["Data"]["fields"]:
incoming = cls._create_field(name, field, provider_name, force_optional=True)
incoming = cls._create_field(
name, field, provider_name, force_optional=True
)
if incoming.name in extra:
current = DataclassField(*extra[incoming.name])

View File

@@ -13,6 +13,7 @@ from openbb_core.app.provider_interface import (
get_provider_interface,
)
class Query:
"""Query class."""

View File

@@ -1,7 +1,6 @@
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###
from openbb_core.app.static.container import Container

View File

@@ -13,7 +13,7 @@ class Provider:
name: str,
description: str,
required_credentials: Optional[List[str]],
fetcher_list: List[Fetcher],
fetcher_dict: Dict[str, Fetcher],
) -> None:
"""Initialize the provider."""
self.name = name
@@ -25,9 +25,4 @@ class Provider:
for rq in required_credentials:
self.formatted_credentials.append(f"{self.name.lower()}_{rq}")
self.fetcher_list = fetcher_list
self.fetcher_dict: Dict[str, Fetcher] = {}
for fetcher in fetcher_list:
model_name = fetcher().query_params_type.__name__.replace("QueryParams", "")
self.fetcher_dict[model_name] = fetcher
self.fetcher_dict = fetcher_dict

View File

@@ -5,6 +5,7 @@ from openbb_provider.registry import Registry, RegistryLoader
MapType = Dict[str, Dict[str, Dict[str, Dict[str, Any]]]]
class RegistryMap:
"""Class to store information about providers in the registry."""