From f61ffb56ca722d40bed8d6ad0350b05a4cec735c Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Wed, 12 Jul 2023 18:39:21 +0530 Subject: [PATCH] Add `forex.pairs` to get available forex pairs --- .../builtin_providers/fmp/forex_pairs.py | 51 +++++++++++++++++++ .../builtin_providers/fmp/provider.py | 2 + .../openbb_provider/model/data/forex_pairs.py | 34 +++++++++++++ .../builtin_extensions/forex/forex_router.py | 14 ++++- 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 openbb_providers/builtin_providers/fmp/forex_pairs.py create mode 100644 openbb_providers/openbb_provider/model/data/forex_pairs.py diff --git a/openbb_providers/builtin_providers/fmp/forex_pairs.py b/openbb_providers/builtin_providers/fmp/forex_pairs.py new file mode 100644 index 00000000000..e13bc73ddaa --- /dev/null +++ b/openbb_providers/builtin_providers/fmp/forex_pairs.py @@ -0,0 +1,51 @@ +"""FMP Forex available pairs fetcher.""" + +# IMPORT STANDARD +from typing import Dict, List, Optional + +# IMPORT INTERNAL +from openbb_provider.model.abstract.data import Data, QueryParams +from openbb_provider.model.data.forex_pairs import ForexPairsData, ForexPairsQueryParams +from openbb_provider.provider.abstract.fetcher import Fetcher +from openbb_provider.provider.provider_helpers import data_transformer + +from builtin_providers.fmp.helpers import get_data_many + + +class FMPForexPairsQueryParams(QueryParams): + """FMP Forex available pairs query. + + Source: https://site.financialmodelingprep.com/developer/docs/#Historical-Forex-Price + + """ + + +class FMPForexPairsData(Data): + """FMP Forex available pairs data.""" + + +class FMPForexPairsFetcher( + Fetcher[ + ForexPairsQueryParams, + ForexPairsData, + FMPForexPairsQueryParams, + FMPForexPairsData, + ] +): + @staticmethod + def transform_query( + query: ForexPairsQueryParams, extra_params: Optional[Dict] = None + ) -> FMPForexPairsQueryParams: + return FMPForexPairsQueryParams() + + @staticmethod + def extract_data( + query: FMPForexPairsQueryParams, api_key: str + ) -> List[FMPForexPairsData]: + 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) + + @staticmethod + def transform_data(data: List[FMPForexPairsData]) -> List[ForexPairsData]: + return data_transformer(data, ForexPairsData) diff --git a/openbb_providers/builtin_providers/fmp/provider.py b/openbb_providers/builtin_providers/fmp/provider.py index 7591f4fb31d..48008b60e8a 100644 --- a/openbb_providers/builtin_providers/fmp/provider.py +++ b/openbb_providers/builtin_providers/fmp/provider.py @@ -24,6 +24,7 @@ from builtin_providers.fmp.executive_compensation import FMPExecutiveCompensatio from builtin_providers.fmp.executives import FMPKeyExecutivesFetcher from builtin_providers.fmp.forex_eod import FMPForexEODFetcher from builtin_providers.fmp.forex_price import FMPForexPriceFetcher +from builtin_providers.fmp.forex_pairs import FMPForexPairsFetcher from builtin_providers.fmp.global_news import FMPGlobalNewsFetcher from builtin_providers.fmp.historical_dividends import FMPHistoricalDividendsFetcher from builtin_providers.fmp.historical_stock_splits import ( @@ -92,5 +93,6 @@ fmp_provider = Provider( FMPMajorIndicesPriceFetcher, FMPForexEODFetcher, FMPForexPriceFetcher, + FMPForexPairsFetcher, ], ) diff --git a/openbb_providers/openbb_provider/model/data/forex_pairs.py b/openbb_providers/openbb_provider/model/data/forex_pairs.py new file mode 100644 index 00000000000..a85af6387d4 --- /dev/null +++ b/openbb_providers/openbb_provider/model/data/forex_pairs.py @@ -0,0 +1,34 @@ +"""Forex available pairs data model.""" + + +from typing import Optional + +from openbb_provider.model.abstract.data import Data, QueryParams + + +class ForexPairsQueryParams(QueryParams): + """Forex available pairs query.""" + + +class ForexPairsData(Data): + """Forex available pairs data. + + Returns + ------- + symbol : str + The symbol of the currency pair. + name : str + The name of the currency pair separated by '/'. + currency : str + The base currency of the currency pair. + stockExchange : str + The stock exchange of the currency pair. + exchangeShortName : str + The short name of the stock exchange of the currency pair. + """ + + symbol: str + name: str + currency: str + stockExchange: Optional[str] + exchangeShortName: Optional[str] diff --git a/openbb_sdk/builtin_extensions/forex/forex_router.py b/openbb_sdk/builtin_extensions/forex/forex_router.py index 0f448143a63..76e48e6b3ef 100644 --- a/openbb_sdk/builtin_extensions/forex/forex_router.py +++ b/openbb_sdk/builtin_extensions/forex/forex_router.py @@ -8,16 +8,28 @@ from openbb_sdk_core.app.provider_interface import ( ) from openbb_sdk_core.app.query import Query from openbb_sdk_core.app.router import Router +from pydantic import BaseModel router = Router(prefix="") +@router.command(query="ForexPairs") +def pairs( + cc: CommandContext, + provider_choices: ProviderChoices, + standard_params: StandardParams, + extra_params: ExtraParams, +) -> CommandOutput[BaseModel]: + """Forex Available Pairs.""" + return CommandOutput(results=Query(**locals()).execute()) + + @router.command(query="ForexEOD") def load( cc: CommandContext, provider_choices: ProviderChoices, standard_params: StandardParams, extra_params: ExtraParams, -) -> CommandOutput[Empty]: # type: ignore +) -> CommandOutput[BaseModel]: """Forex Intraday Price.""" return CommandOutput(results=Query(**locals()).execute())