Added economy.available_indices

This commit is contained in:
Pratyush Shukla
2023-07-19 02:30:32 +05:30
parent 2fdff38f72
commit 0c67f469d2
4 changed files with 113 additions and 7 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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,
],
)

View File

@@ -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