push provider imports to provider interface

This commit is contained in:
montezdesousa
2023-07-15 17:34:19 +01:00
parent 7782462a42
commit 492aae6e37
5 changed files with 14 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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