mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 07:23:25 +00:00
Rename the fmp search -> screener (#5744)
* Rename the fmp search -> screener * misses some * i cant copy paste
This commit is contained in:
@@ -969,6 +969,44 @@ def test_equity_search(params, headers):
|
||||
assert result.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"params",
|
||||
[
|
||||
(
|
||||
{
|
||||
"industry": "REIT",
|
||||
"sector": "Real Estate",
|
||||
"mktcap_min": None,
|
||||
"mktcap_max": None,
|
||||
"price_min": None,
|
||||
"price_max": None,
|
||||
"volume_min": None,
|
||||
"volume_max": None,
|
||||
"dividend_min": None,
|
||||
"dividend_max": None,
|
||||
"is_active": True,
|
||||
"is_etf": False,
|
||||
"beta_min": None,
|
||||
"beta_max": None,
|
||||
"country": "US",
|
||||
"exchange": "nyse",
|
||||
"limit": None,
|
||||
"provider": "fmp",
|
||||
}
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.integration
|
||||
def test_equity_screener(params, headers):
|
||||
params = {p: v for p, v in params.items() if v}
|
||||
|
||||
query_str = get_querystring(params, [])
|
||||
url = f"http://0.0.0.0:8000/api/v1/equity/screener?{query_str}"
|
||||
result = requests.get(url, headers=headers, timeout=10)
|
||||
assert isinstance(result, requests.Response)
|
||||
assert result.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"params",
|
||||
[
|
||||
|
||||
@@ -897,6 +897,41 @@ def test_equity_search(params, obb):
|
||||
assert len(result.results) > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"params",
|
||||
[
|
||||
(
|
||||
{
|
||||
"industry": "REIT",
|
||||
"sector": "Real Estate",
|
||||
"mktcap_min": None,
|
||||
"mktcap_max": None,
|
||||
"price_min": None,
|
||||
"price_max": None,
|
||||
"volume_min": None,
|
||||
"volume_max": None,
|
||||
"dividend_min": None,
|
||||
"dividend_max": None,
|
||||
"is_active": True,
|
||||
"is_etf": False,
|
||||
"beta_min": None,
|
||||
"beta_max": None,
|
||||
"country": "US",
|
||||
"exchange": "nyse",
|
||||
"limit": None,
|
||||
"provider": "fmp",
|
||||
}
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.integration
|
||||
def test_equity_screener(params, obb):
|
||||
result = obb.equity.screener(**params)
|
||||
assert result
|
||||
assert isinstance(result, OBBject)
|
||||
assert len(result.results) > 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"params",
|
||||
[
|
||||
|
||||
@@ -46,6 +46,17 @@ def search(
|
||||
return OBBject(results=Query(**locals()).execute())
|
||||
|
||||
|
||||
@router.command(model="EquityScreener")
|
||||
def screener(
|
||||
cc: CommandContext,
|
||||
provider_choices: ProviderChoices,
|
||||
standard_params: StandardParams,
|
||||
extra_params: ExtraParams,
|
||||
) -> OBBject[BaseModel]:
|
||||
"""Equity Screen. Screen for companies meeting various criteria."""
|
||||
return OBBject(results=Query(**locals()).execute())
|
||||
|
||||
|
||||
@router.command(model="EquityInfo")
|
||||
def profile(
|
||||
cc: CommandContext,
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Equity Screener data model."""
|
||||
|
||||
from typing import List, Set, Union
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
|
||||
from openbb_provider.abstract.data import Data
|
||||
from openbb_provider.abstract.query_params import QueryParams
|
||||
from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS
|
||||
|
||||
|
||||
class EquityScreenerQueryParams(QueryParams):
|
||||
"""Company Screener Query Params."""
|
||||
|
||||
|
||||
class EquityScreenerData(Data):
|
||||
"""Company Screener Data."""
|
||||
|
||||
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
|
||||
name: str = Field(description="Name of the company.")
|
||||
|
||||
@field_validator("symbol", mode="before", check_fields=False)
|
||||
@classmethod
|
||||
def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
|
||||
"""Convert symbol to uppercase."""
|
||||
if isinstance(v, str):
|
||||
return v.upper()
|
||||
return ",".join([symbol.upper() for symbol in list(v)])
|
||||
@@ -22,7 +22,7 @@ from openbb_fmp.models.equity_historical import FMPEquityHistoricalFetcher
|
||||
from openbb_fmp.models.equity_ownership import FMPEquityOwnershipFetcher
|
||||
from openbb_fmp.models.equity_peers import FMPEquityPeersFetcher
|
||||
from openbb_fmp.models.equity_quote import FMPEquityQuoteFetcher
|
||||
from openbb_fmp.models.equity_search import FMPEquitySearchFetcher
|
||||
from openbb_fmp.models.equity_screener import FMPEquityScreenerFetcher
|
||||
from openbb_fmp.models.equity_valuation_multiples import (
|
||||
FMPEquityValuationMultiplesFetcher,
|
||||
)
|
||||
@@ -90,7 +90,7 @@ fmp_provider = Provider(
|
||||
"EquityOwnership": FMPEquityOwnershipFetcher,
|
||||
"EquityPeers": FMPEquityPeersFetcher,
|
||||
"EquityQuote": FMPEquityQuoteFetcher,
|
||||
"EquitySearch": FMPEquitySearchFetcher,
|
||||
"EquityScreener": FMPEquityScreenerFetcher,
|
||||
"EquityValuationMultiples": FMPEquityValuationMultiplesFetcher,
|
||||
"EtfCountries": FMPEtfCountriesFetcher,
|
||||
"EtfHoldings": FMPEtfHoldingsFetcher,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""FMP Equity Search fetcher."""
|
||||
"""FMP Equity Screener fetcher."""
|
||||
|
||||
from typing import Any, Dict, List, Literal, Optional
|
||||
|
||||
@@ -6,15 +6,15 @@ import pandas as pd
|
||||
from openbb_fmp.utils.definitions import EXCHANGES, SECTORS
|
||||
from openbb_fmp.utils.helpers import create_url, get_data
|
||||
from openbb_provider.abstract.fetcher import Fetcher
|
||||
from openbb_provider.standard_models.equity_search import (
|
||||
EquitySearchData,
|
||||
EquitySearchQueryParams,
|
||||
from openbb_provider.standard_models.equity_screener import (
|
||||
EquityScreenerData,
|
||||
EquityScreenerQueryParams,
|
||||
)
|
||||
from pydantic import Field
|
||||
|
||||
|
||||
class FMPEquitySearchQueryParams(EquitySearchQueryParams):
|
||||
"""FMP Equity Search Query Params."""
|
||||
class FMPEquityScreenerQueryParams(EquityScreenerQueryParams):
|
||||
"""FMP Equity Screener Query Params."""
|
||||
|
||||
__alias_dict__ = {
|
||||
"mktcap_min": "marketCapMoreThan",
|
||||
@@ -91,8 +91,8 @@ class FMPEquitySearchQueryParams(EquitySearchQueryParams):
|
||||
)
|
||||
|
||||
|
||||
class FMPEquitySearchData(EquitySearchData):
|
||||
"""FMP Equity Search Data."""
|
||||
class FMPEquityScreenerData(EquityScreenerData):
|
||||
"""FMP Equity Screener Data."""
|
||||
|
||||
__alias_dict__ = {
|
||||
"name": "companyName",
|
||||
@@ -141,22 +141,22 @@ class FMPEquitySearchData(EquitySearchData):
|
||||
)
|
||||
|
||||
|
||||
class FMPEquitySearchFetcher(
|
||||
class FMPEquityScreenerFetcher(
|
||||
Fetcher[
|
||||
FMPEquitySearchQueryParams,
|
||||
List[FMPEquitySearchData],
|
||||
FMPEquityScreenerQueryParams,
|
||||
List[FMPEquityScreenerData],
|
||||
]
|
||||
):
|
||||
"""Transform the query, extract and transform the data from the FMP endpoints."""
|
||||
|
||||
@staticmethod
|
||||
def transform_query(params: Dict[str, Any]) -> FMPEquitySearchQueryParams:
|
||||
def transform_query(params: Dict[str, Any]) -> FMPEquityScreenerQueryParams:
|
||||
"""Transform the query."""
|
||||
return FMPEquitySearchQueryParams(**params)
|
||||
return FMPEquityScreenerQueryParams(**params)
|
||||
|
||||
@staticmethod
|
||||
def extract_data(
|
||||
query: FMPEquitySearchQueryParams,
|
||||
query: FMPEquityScreenerQueryParams,
|
||||
credentials: Optional[Dict[str, str]],
|
||||
**kwargs: Any,
|
||||
) -> List[Dict]:
|
||||
@@ -173,8 +173,8 @@ class FMPEquitySearchFetcher(
|
||||
|
||||
@staticmethod
|
||||
def transform_data(
|
||||
query: FMPEquitySearchQueryParams, data: List[Dict], **kwargs: Any
|
||||
) -> List[FMPEquitySearchData]:
|
||||
query: FMPEquityScreenerQueryParams, data: List[Dict], **kwargs: Any
|
||||
) -> List[FMPEquityScreenerData]:
|
||||
"""Return the transformed data."""
|
||||
results = pd.DataFrame(data)
|
||||
if len(results) == 0:
|
||||
@@ -184,21 +184,12 @@ class FMPEquitySearchFetcher(
|
||||
results["sector"].str.contains(query.industry, case=False)
|
||||
| results["industry"].str.contains(query.industry, case=False)
|
||||
]
|
||||
if query.query:
|
||||
results = results[
|
||||
results["companyName"].str.contains(query.query, case=False)
|
||||
| results["exchangeShortName"].str.contains(query.query, case=False)
|
||||
| results["exchange"].str.contains(query.query, case=False)
|
||||
| results["sector"].str.contains(query.query, case=False)
|
||||
| results["industry"].str.contains(query.query, case=False)
|
||||
| results["country"].str.contains(query.query, case=False)
|
||||
]
|
||||
results["companyName"] = results["companyName"].fillna("-").replace("-", "")
|
||||
for col in results:
|
||||
if results[col].dtype in ("int", "float"):
|
||||
results[col] = results[col].fillna(0).replace(0, None)
|
||||
return [
|
||||
FMPEquitySearchData.model_validate(d)
|
||||
FMPEquityScreenerData.model_validate(d)
|
||||
for d in results.sort_values(by="marketCap", ascending=False).to_dict(
|
||||
"records"
|
||||
)
|
||||
@@ -25,7 +25,7 @@ from openbb_fmp.models.equity_historical import FMPEquityHistoricalFetcher
|
||||
from openbb_fmp.models.equity_ownership import FMPEquityOwnershipFetcher
|
||||
from openbb_fmp.models.equity_peers import FMPEquityPeersFetcher
|
||||
from openbb_fmp.models.equity_quote import FMPEquityQuoteFetcher
|
||||
from openbb_fmp.models.equity_search import FMPEquitySearchFetcher
|
||||
from openbb_fmp.models.equity_screener import FMPEquityScreenerFetcher
|
||||
from openbb_fmp.models.equity_valuation_multiples import (
|
||||
FMPEquityValuationMultiplesFetcher,
|
||||
)
|
||||
@@ -464,10 +464,10 @@ def test_fmp_equity_quote_fetcher(credentials=test_credentials):
|
||||
|
||||
|
||||
@pytest.mark.record_http
|
||||
def test_fmp_equity_search_fetcher(credentials=test_credentials):
|
||||
def test_fmp_equity_screener_fetcher(credentials=test_credentials):
|
||||
params = {"query": "midstream", "sector": "Energy", "beta_max": 0.5}
|
||||
|
||||
fetcher = FMPEquitySearchFetcher()
|
||||
fetcher = FMPEquityScreenerFetcher()
|
||||
result = fetcher.test(params, credentials)
|
||||
assert result is None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user