mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 06:51:38 +00:00
Add forex.pairs to get available forex pairs
This commit is contained in:
51
openbb_providers/builtin_providers/fmp/forex_pairs.py
Normal file
51
openbb_providers/builtin_providers/fmp/forex_pairs.py
Normal file
@@ -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)
|
||||
@@ -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,
|
||||
],
|
||||
)
|
||||
|
||||
34
openbb_providers/openbb_provider/model/data/forex_pairs.py
Normal file
34
openbb_providers/openbb_provider/model/data/forex_pairs.py
Normal file
@@ -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]
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user