Skip to content

Commit

Permalink
Fix price performance not parsed correctly when there is only 1 ticker (
Browse files Browse the repository at this point in the history
  • Loading branch information
piiq committed Nov 8, 2023
1 parent e5e10d3 commit da4de4b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ def extract_data(
# Get price performance for the holdings
holdings_performance: list = []
for holding_chunk in chunks:
holdings_str = ",".join(holding_chunk)
holdings_str = (
",".join(holding_chunk) if len(holding_chunk) > 1 else holding_chunk[0]
)
_performance = FMPPricePerformanceFetcher().extract_data(
FMPPricePerformanceFetcher.transform_query({"symbol": holdings_str}),
credentials,
**kwargs,
)
holdings_performance.extend(_performance[d] for d in _performance)
holdings_performance.extend(_performance)
return holdings_performance

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any, Dict, List, Optional

from openbb_fmp.utils.helpers import create_url, get_data_one
from openbb_fmp.utils.helpers import create_url, get_data_many
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.standard_models.recent_performance import (
RecentPerformanceData,
Expand Down Expand Up @@ -54,7 +54,7 @@ def extract_data(
query: FMPPricePerformanceQueryParams,
credentials: Optional[Dict[str, str]],
**kwargs: Any,
) -> Dict:
) -> List[Dict]:
"""Return the raw data from the FMP endpoint."""
api_key = credentials.get("fmp_api_key") if credentials else ""

Expand All @@ -64,14 +64,13 @@ def extract_data(
api_key=api_key,
exclude=["symbol"],
)
return get_data_one(url, **kwargs)
return get_data_many(url, **kwargs)

@staticmethod
def transform_data(
query: FMPPricePerformanceQueryParams,
data: Dict,
data: List[Dict],
**kwargs: Any,
) -> List[FMPPricePerformanceData]:
"""Return the transformed data."""
data = data if 0 in data else {0: data}
return [FMPPricePerformanceData.model_validate(data[i]) for i in data]
return [FMPPricePerformanceData.model_validate(i) for i in data]

0 comments on commit da4de4b

Please sign in to comment.