Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/disc router #5616

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions openbb_platform/extensions/etf/integration/test_etf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,48 @@ def test_etf_price_performance(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10, "provider": "wsj"})],
)
@pytest.mark.integration
def test_etf_disc_gainers(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/stocks/disc/gainers?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10, "provider": "wsj"})],
)
@pytest.mark.integration
def test_etf_disc_losers(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/stocks/disc/losers?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10, "provider": "wsj"})],
)
@pytest.mark.integration
def test_etf_disc_active(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/stocks/disc/active?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
42 changes: 42 additions & 0 deletions openbb_platform/extensions/etf/integration/test_etf_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,45 @@ def test_etf_price_performance(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10})],
)
@pytest.mark.integration
def test_etf_disc_gainers(params, obb):
params = {p: v for p, v in params.items() if v}

result = obb.stocks.disc.gainers(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10})],
)
@pytest.mark.integration
def test_etf_disc_losers(params, obb):
params = {p: v for p, v in params.items() if v}

result = obb.stocks.disc.losers(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10})],
)
@pytest.mark.integration
def test_etf_disc_active(params, obb):
params = {p: v for p, v in params.items() if v}

result = obb.stocks.disc.active(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Disc router for ETFs."""
from openbb_core.app.model.command_context import CommandContext
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.provider_interface import (
Expand All @@ -12,34 +13,34 @@
router = Router(prefix="/disc")


@router.command(model="EquityGainers")
@router.command(model="ETFGainers")
def gainers(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Get the top Equity gainers."""
"""Get the top ETF gainers."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="EquityLosers")
@router.command(model="ETFLosers")
def losers(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Get the top Equity losers."""
"""Get the top ETF losers."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="EquityActive")
@router.command(model="ETFActive")
def active(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Get the most active Equities."""
"""Get the most active ETFs."""
return OBBject(results=Query(**locals()).execute())
3 changes: 3 additions & 0 deletions openbb_platform/extensions/etf/openbb_etf/etf_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
from openbb_core.app.router import Router
from pydantic import BaseModel

from openbb_etf.disc.disc_router import router as disc_router

router = Router(prefix="")
router.include_router(disc_router)


# pylint: disable=unused-argument
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from pydantic import BaseModel

from openbb_stocks.ca.ca_router import router as ca_router
from openbb_stocks.disc.disc_router import router as disc_router
from openbb_stocks.fa.fa_router import router as fa_router
from openbb_stocks.options.options_router import router as options_router

Expand All @@ -28,7 +27,6 @@
router.include_router(fa_router)
router.include_router(ca_router)
router.include_router(options_router)
router.include_router(disc_router)

# router.include_router(dps_router)
# router.include_router(gov_router)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Available Indices data model."""
"""ETF performance data model."""
from datetime import date as dateType

from pydantic import Field
Expand All @@ -8,8 +8,8 @@
from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS, QUERY_DESCRIPTIONS


class AssetPerformanceQueryParams(QueryParams):
"""Asset Performance QueryParams."""
class ETFPerformanceQueryParams(QueryParams):
"""ETF Performance QueryParams."""

sort: str = Field(
default="desc",
Expand All @@ -21,8 +21,8 @@ class AssetPerformanceQueryParams(QueryParams):
)


class AssetPerformanceData(Data):
"""Asset performance data."""
class ETFPerformanceData(Data):
"""ETF performance data."""

symbol: str = Field(
description=DATA_DESCRIPTIONS.get("symbol", ""),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""FMP Price Performance Model"""

"""FMP Price Performance Model."""

from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -66,7 +65,9 @@ def extract_data(

@staticmethod
def transform_data(
query: FMPPricePerformanceQueryParams,
data: Dict,
**kwargs: Any,
) -> List[FMPPricePerformanceData]:
"""Transform the raw data into the standard model."""
return [FMPPricePerformanceData.model_validate(data[i]) for i in data]
6 changes: 3 additions & 3 deletions openbb_platform/providers/wsj/openbb_wsj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
The WSJ is the largest newspaper in the United States, by circulation.
""",
fetcher_dict={
"DiscGainers": WSJGainersFetcher,
"DiscLosers": WSJLosersFetcher,
"DiscActive": WSJActiveFetcher,
"ETFGainers": WSJGainersFetcher,
"ETFLosers": WSJLosersFetcher,
"ETFActive": WSJActiveFetcher,
},
)
12 changes: 6 additions & 6 deletions openbb_platform/providers/wsj/openbb_wsj/models/active.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

import requests
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.standard_models.asset_performance import (
AssetPerformanceData,
AssetPerformanceQueryParams,
from openbb_provider.standard_models.etf_performance import (
ETFPerformanceData,
ETFPerformanceQueryParams,
)
from pydantic import Field, field_validator


class WSJActiveQueryParams(AssetPerformanceQueryParams):
class WSJActiveQueryParams(ETFPerformanceQueryParams):
"""WSJ asset performance active QueryParams.

Source: https://www.wsj.com/market-data/mutualfunds-etfs/etfmovers
"""


class WSJActiveData(AssetPerformanceData):
class WSJActiveData(ETFPerformanceData):
"""WSJ asset performance active Data."""

__alias_dict__ = {
Expand Down Expand Up @@ -87,7 +87,7 @@ def extract_data(

@staticmethod
def transform_data(
query: AssetPerformanceQueryParams,
query: ETFPerformanceQueryParams,
data: List[Dict],
**kwargs: Any,
) -> List[WSJActiveData]:
Expand Down
16 changes: 8 additions & 8 deletions openbb_platform/providers/wsj/openbb_wsj/models/gainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

import requests
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.standard_models.asset_performance import (
AssetPerformanceData,
AssetPerformanceQueryParams,
from openbb_provider.standard_models.etf_performance import (
ETFPerformanceData,
ETFPerformanceQueryParams,
)
from pydantic import Field, field_validator


class WSJGainersQueryParams(AssetPerformanceQueryParams):
class WSJGainersQueryParams(ETFPerformanceQueryParams):
"""WSJ asset performance gainers QueryParams.

Source: https://www.wsj.com/market-data/mutualfunds-etfs/etfmovers
"""


class WSJGainersData(AssetPerformanceData):
class WSJGainersData(ETFPerformanceData):
"""WSJ asset performance gainers Data."""

__alias_dict__ = {
Expand All @@ -29,8 +29,8 @@ class WSJGainersData(AssetPerformanceData):
"date": "timestamp",
}

bluegrass_channel: str = Field(
description="Bluegrass channel.",
bluegrass_channel: Optional[str] = Field(
description="Bluegrass channel.", default=None
)
country: str = Field(
description="Country of the entity.",
Expand Down Expand Up @@ -90,7 +90,7 @@ def extract_data(

@staticmethod
def transform_data(
query: AssetPerformanceQueryParams,
query: ETFPerformanceQueryParams,
data: List[Dict],
**kwargs: Any,
) -> List[WSJGainersData]:
Expand Down
16 changes: 8 additions & 8 deletions openbb_platform/providers/wsj/openbb_wsj/models/losers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

import requests
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.standard_models.asset_performance import (
AssetPerformanceData,
AssetPerformanceQueryParams,
from openbb_provider.standard_models.etf_performance import (
ETFPerformanceData,
ETFPerformanceQueryParams,
)
from pydantic import Field, field_validator


class WSJLosersQueryParams(AssetPerformanceQueryParams):
class WSJLosersQueryParams(ETFPerformanceQueryParams):
"""WSJ asset performance losers QueryParams.

Source: https://www.wsj.com/market-data/mutualfunds-etfs/etfmovers
"""


class WSJLosersData(AssetPerformanceData):
class WSJLosersData(ETFPerformanceData):
"""WSJ asset performance losers Data."""

__alias_dict__ = {
Expand All @@ -29,8 +29,8 @@ class WSJLosersData(AssetPerformanceData):
"date": "timestamp",
}

bluegrass_channel: str = Field(
description="Bluegrass channel.",
bluegrass_channel: Optional[str] = Field(
description="Bluegrass channel.", default=None
)
country: str = Field(
description="Country of the entity.",
Expand Down Expand Up @@ -90,7 +90,7 @@ def extract_data(

@staticmethod
def transform_data(
query: AssetPerformanceQueryParams,
query: ETFPerformanceQueryParams,
data: List[Dict],
**kwargs: Any,
) -> List[WSJLosersData]:
Expand Down
Loading