diff --git a/openbb_sdk/extensions/economy/openbb_economy/economy_router.py b/openbb_sdk/extensions/economy/openbb_economy/economy_router.py index 70b3f864fd9..59223f42b5c 100644 --- a/openbb_sdk/extensions/economy/openbb_economy/economy_router.py +++ b/openbb_sdk/extensions/economy/openbb_economy/economy_router.py @@ -46,22 +46,26 @@ def cpi_options( return CommandOutput(results=Empty()) -@router.command +@router.command(model="MajorIndicesPrice") def index( cc: CommandContext, provider_choices: ProviderChoices, -) -> CommandOutput[Empty]: # type: ignore - """Get index from yfinance.""" - return CommandOutput(results=Empty()) + standard_params: StandardParams, + extra_params: ExtraParams, +) -> CommandOutput[BaseModel]: + """Get OHLCV data for an index.""" + return CommandOutput(results=Query(**locals()).execute()) -@router.command +@router.command(model="AvailableIndices") def available_indices( cc: CommandContext, provider_choices: ProviderChoices, -) -> CommandOutput[Empty]: + standard_params: StandardParams, + extra_params: ExtraParams, +) -> CommandOutput[BaseModel]: """AVAILABLE_INDICES.""" - return CommandOutput(results=Empty()) + return CommandOutput(results=Query(**locals()).execute()) @router.command diff --git a/openbb_sdk/providers/fmp/openbb_fmp/available_indices.py b/openbb_sdk/providers/fmp/openbb_fmp/available_indices.py new file mode 100644 index 00000000000..cb83a1f0213 --- /dev/null +++ b/openbb_sdk/providers/fmp/openbb_fmp/available_indices.py @@ -0,0 +1,64 @@ +"""FMP Available Indices fetcher.""" + +# IMPORT STANDARD +from typing import Dict, List, Optional + +# IMPORT INTERNAL +from openbb_provider.abstract.data import Data, QueryParams +from openbb_provider.abstract.fetcher import Fetcher +from openbb_provider.helpers import data_transformer +from openbb_provider.models.available_indices import ( + AvailableIndicesData, + AvailableIndicesQueryParams, +) + +from .helpers import get_data_many + +from pydantic import Field + + +class FMPAvailableIndicesQueryParams(QueryParams): + """FMP Available Indices query. + + Source: https://site.financialmodelingprep.com/developer/docs/#Historical-stock-index-prices + + """ + + +class FMPAvailableIndicesData(Data): + """FMP Available Indices data.""" + + symbol: str + name: Optional[str] + currency: Optional[str] + stockExchange: str = Field(alias="stock_exchange") + exchangeShortName: str = Field(alias="exchange_short_name") + + +class FMPAvailableIndicesFetcher( + Fetcher[ + AvailableIndicesQueryParams, + AvailableIndicesData, + FMPAvailableIndicesQueryParams, + FMPAvailableIndicesData, + ] +): + @staticmethod + def transform_query( + query: AvailableIndicesQueryParams, extra_params: Optional[Dict] = None + ) -> FMPAvailableIndicesQueryParams: + return FMPAvailableIndicesQueryParams() + + @staticmethod + def extract_data( + query: FMPAvailableIndicesQueryParams, api_key: str + ) -> List[FMPAvailableIndicesData]: + base_url = "https://financialmodelingprep.com/api/v3" + url = f"{base_url}/symbol/available-indexes?apikey={api_key}" + return get_data_many(url, FMPAvailableIndicesData) + + @staticmethod + def transform_data( + data: List[FMPAvailableIndicesData], + ) -> List[AvailableIndicesData]: + return data_transformer(data, AvailableIndicesData) diff --git a/openbb_sdk/providers/fmp/openbb_fmp/provider.py b/openbb_sdk/providers/fmp/openbb_fmp/provider.py index 7e4a58046ef..dc9c01fe50c 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/provider.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/provider.py @@ -8,6 +8,7 @@ from openbb_provider.abstract.provider import Provider, ProviderNameType from .analyst_estimates import FMPAnalystEstimatesFetcher +from .available_indices import FMPAvailableIndicesFetcher from .balance_sheet import FMPBalanceSheetFetcher from .cash_flow import FMPCashFlowStatementFetcher from .company_profile import FMPCompanyProfileFetcher @@ -94,5 +95,6 @@ fmp_provider = Provider( FMPStockPeersFetcher, FMPStockMultiplesFetcher, FMPHistoricalEmployeesFetcher, + FMPAvailableIndicesFetcher, ], ) diff --git a/openbb_sdk/sdk/provider/openbb_provider/models/available_indices.py b/openbb_sdk/sdk/provider/openbb_provider/models/available_indices.py new file mode 100644 index 00000000000..3fa735288f5 --- /dev/null +++ b/openbb_sdk/sdk/provider/openbb_provider/models/available_indices.py @@ -0,0 +1,36 @@ +"""Available Indices data model.""" + + +from typing import Optional + +from openbb_provider.abstract.data import Data, QueryParams + + +class AvailableIndicesQueryParams(QueryParams): + """Available Indices query.""" + + +class AvailableIndicesData(Data): + """Available Indices data. + + Returns the major indices from Dow Jones, Nasdaq and, S&P 500. + + Returns + ------- + symbol : str + The symbol of the index. + name : Optional[str] + The name of the index. + currency : Optional[str] + The currency the index is traded in. + stock_exchange : str + The stock exchange where the index is listed. + exchange_short_name : str + The short name of the stock exchange where the index is listed. + """ + + symbol: str + name: Optional[str] + currency: Optional[str] + stock_exchange: str + exchange_short_name: str