diff --git a/openbb_sdk/extensions/crypto/openbb_crypto/crypto_router.py b/openbb_sdk/extensions/crypto/openbb_crypto/crypto_router.py index e7629664b88..fa5a74886bd 100644 --- a/openbb_sdk/extensions/crypto/openbb_crypto/crypto_router.py +++ b/openbb_sdk/extensions/crypto/openbb_crypto/crypto_router.py @@ -7,7 +7,7 @@ from openbb_core.app.provider_interface import ( ) from openbb_core.app.query import Query from openbb_core.app.router import Router -from openbb_provider.abstract.data import Data +from pydantic import BaseModel router = Router(prefix="") @@ -19,6 +19,6 @@ def load( provider_choices: ProviderChoices, standard_params: StandardParams, extra_params: ExtraParams, -) -> CommandOutput[Data]: +) -> CommandOutput[BaseModel]: """Crypto Intraday Price.""" return CommandOutput(results=Query(**locals()).execute()) diff --git a/openbb_sdk/extensions/forex/openbb_forex/forex_router.py b/openbb_sdk/extensions/forex/openbb_forex/forex_router.py index a712b678e70..308a90fd131 100644 --- a/openbb_sdk/extensions/forex/openbb_forex/forex_router.py +++ b/openbb_sdk/extensions/forex/openbb_forex/forex_router.py @@ -7,7 +7,7 @@ from openbb_core.app.provider_interface import ( ) from openbb_core.app.query import Query from openbb_core.app.router import Router -from openbb_provider.abstract.data import Data +from pydantic import BaseModel router = Router(prefix="") @@ -19,7 +19,7 @@ def pairs( provider_choices: ProviderChoices, standard_params: StandardParams, extra_params: ExtraParams, -) -> CommandOutput[Data]: +) -> CommandOutput[BaseModel]: """Forex Available Pairs.""" return CommandOutput(results=Query(**locals()).execute()) @@ -31,6 +31,6 @@ def load( provider_choices: ProviderChoices, standard_params: StandardParams, extra_params: ExtraParams, -) -> CommandOutput[Data]: +) -> CommandOutput[BaseModel]: """Forex Intraday Price.""" return CommandOutput(results=Query(**locals()).execute()) diff --git a/openbb_sdk/sdk/core/openbb_core/app/provider_interface.py b/openbb_sdk/sdk/core/openbb_core/app/provider_interface.py index eec0a4e2eec..b0f2386037d 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/provider_interface.py +++ b/openbb_sdk/sdk/core/openbb_core/app/provider_interface.py @@ -1,8 +1,9 @@ from dataclasses import dataclass, make_dataclass -from typing import Any, Dict, List, Literal, Optional, Tuple, Union +from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union from fastapi import Query from openbb_provider.map import build_provider_mapping +from openbb_provider.registry import build_provider_registry from pydantic import BaseConfig, BaseModel, Extra, Field, create_model @@ -107,6 +108,10 @@ class ProviderInterface: def models(self) -> List[str]: return list(self.__map.keys()) + @property + def registry(self) -> Callable: + return build_provider_registry + @staticmethod def __merge_fields( current: DataclassField, incoming: DataclassField, query: bool = False diff --git a/openbb_sdk/sdk/core/openbb_core/app/query.py b/openbb_sdk/sdk/core/openbb_core/app/query.py index 50060fe1c1e..e80bb65a71c 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/query.py +++ b/openbb_sdk/sdk/core/openbb_core/app/query.py @@ -4,8 +4,7 @@ import warnings from dataclasses import asdict from typing import Any, Dict -from openbb_provider.abstract.data import Data -from openbb_provider.registry import build_provider_registry +from pydantic import BaseModel from openbb_core.app.model.abstract.warning import OpenBBWarning from openbb_core.app.model.command_context import CommandContext @@ -68,10 +67,10 @@ class Query: standard_params.__name__ = self.name + "QueryParams" # type: ignore return standard_params - def execute(self) -> Data: + def execute(self) -> BaseModel: """Execute the query.""" - registry = build_provider_registry() + registry = get_provider_interface().registry() creds = self.cc.user_settings.credentials registry.api_keys[self.provider] = getattr(creds, self.provider + "_api_key") # type: ignore diff --git a/openbb_sdk/sdk/core/openbb_core/app/utils.py b/openbb_sdk/sdk/core/openbb_core/app/utils.py index 66a7cb2ef2c..4132a66c6d7 100644 --- a/openbb_sdk/sdk/core/openbb_core/app/utils.py +++ b/openbb_sdk/sdk/core/openbb_core/app/utils.py @@ -3,7 +3,6 @@ from typing import List, Optional, Union import pandas as pd from openbb_provider.abstract.data import Data - def basemodel_to_df(data: List[Data], index: Optional[str] = None) -> pd.DataFrame: """Convert list of BaseModel to a Pandas DataFrame.""" df = pd.DataFrame([d.dict() for d in data])