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

Add stocks disc endpoints #5630

Merged
merged 4 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
64 changes: 61 additions & 3 deletions openbb_platform/extensions/stocks/integration/test_stocks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ def test_stocks_info(params, headers):

@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10, "provider": "wsj"})],
[({"sort": "desc", "provider": "yfinance"})],
)
@pytest.mark.integration
def test_stocks_disc_gainers(params, headers):
Expand All @@ -974,7 +974,7 @@ def test_stocks_disc_gainers(params, headers):

@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10, "provider": "wsj"})],
[({"sort": "desc", "provider": "yfinance"})],
)
@pytest.mark.integration
def test_stocks_disc_losers(params, headers):
Expand All @@ -989,7 +989,7 @@ def test_stocks_disc_losers(params, headers):

@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10, "provider": "wsj"})],
[({"sort": "desc", "provider": "yfinance"})],
)
@pytest.mark.integration
def test_stocks_disc_active(params, headers):
Expand All @@ -1000,3 +1000,61 @@ def test_stocks_disc_active(params, headers):
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL", "provider": "sec"}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this not fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we bump the timeout to 30 it will not

Screenshot 2023-10-31 at 14 50 41

({"limit": 24, "provider": "sec", "symbol": "AAPL", "skip_reports": 1}),
],
)
@pytest.mark.integration
def test_stocks_ftd(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/ftd?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[({"symbol": "AAPL", "provider": "fmp"})],
)
@pytest.mark.integration
def test_stocks_price_performance(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/price_performance?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
(
{
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"limit": 300,
"provider": "intrinio",
}
)
],
)
@pytest.mark.integration
def test_stocks_calendar_ipo(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/calendar_ipo?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ def test_stocks_info(params, obb):

@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10})],
[({"sort": "desc"})],
)
@pytest.mark.integration
def test_stocks_disc_gainers(params, obb):
Expand All @@ -923,7 +923,7 @@ def test_stocks_disc_gainers(params, obb):

@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10})],
[({"sort": "desc"})],
)
@pytest.mark.integration
def test_stocks_disc_losers(params, obb):
Expand All @@ -937,7 +937,7 @@ def test_stocks_disc_losers(params, obb):

@pytest.mark.parametrize(
"params",
[({"sort": "desc", "limit": 10})],
[({"sort": "desc"})],
)
@pytest.mark.integration
def test_stocks_disc_active(params, obb):
Expand All @@ -947,3 +947,57 @@ def test_stocks_disc_active(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[
({"symbol": "AAPL"}),
({"limit": 24, "provider": "sec", "symbol": "AAPL", "skip_reports": 1}),
],
)
@pytest.mark.integration
def test_stocks_ftd(params, obb):
params = {p: v for p, v in params.items() if v}

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


@pytest.mark.parametrize(
"params",
[({"symbol": "AAPL"})],
)
@pytest.mark.integration
def test_stocks_price_performance(params, obb):
params = {p: v for p, v in params.items() if v}

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


@pytest.mark.parametrize(
"params",
[
(
{
"symbol": "AAPL",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"limit": 300,
}
)
],
)
@pytest.mark.integration
def test_stocks_calendar_ipo(params, obb):
params = {p: v for p, v in params.items() if v}

result = obb.stocks.calendar_ipo(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,34 @@
router = Router(prefix="/disc")


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


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


@router.command(model="DiscActive")
@router.command(model="EquityActive")
def active(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Get the most active ETFs."""
"""Get the most active Equities."""
return OBBject(results=Query(**locals()).execute())
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
)
from openbb_core.app.query import Query
from openbb_core.app.router import Router
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
from pydantic import BaseModel

# TODO: Uncomment once they have some commands.
# from openbb_stocks.gov.gov_router import router as gov_router
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Available Indices data model."""
from datetime import date as dateType

from pydantic import Field

from openbb_provider.abstract.data import Data
from openbb_provider.abstract.query_params import QueryParams
from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS, QUERY_DESCRIPTIONS
from pydantic import Field


class AssetPerformanceQueryParams(QueryParams):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Equity performance data model."""

from pydantic import Field

from openbb_provider.abstract.data import Data
from openbb_provider.abstract.query_params import QueryParams
from openbb_provider.utils.descriptions import DATA_DESCRIPTIONS


class EquityPerformanceQueryParams(QueryParams):
"""Equity Performance QueryParams."""

sort: str = Field(
default="desc",
description="Sort order. Possible values: 'asc', 'desc'. Default: 'desc'.",
)


class EquityPerformanceData(Data):
"""Equity performance data."""

symbol: str = Field(
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
name: str = Field(
description="Name of the entity.",
)
price: float = Field(
description="Last price.",
)
change: float = Field(
description="Change in price value.",
)
percent_change: float = Field(
description="Percent change.",
)
volume: float = Field(
description=DATA_DESCRIPTIONS.get("volume", ""),
)
14 changes: 6 additions & 8 deletions openbb_platform/providers/wsj/tests/test_wsj_fetchers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from datetime import datetime
import pytest
from openbb_core.app.service.user_service import UserService
from openbb_wsj.models.active import WSJActiveFetcher
from openbb_wsj.models.gainers import WSJGainersFetcher
from openbb_wsj.models.losers import WSJLosersFetcher
from openbb_wsj.models.active import WSJActiveFetcher

test_credentials = UserService().default_user_settings.credentials.model_dump(mode="json")
test_credentials = UserService().default_user_settings.credentials.model_dump(
mode="json"
)


@pytest.fixture(scope="module")
def vcr_config():
return {
"filter_headers": [("User-Agent", None)],
"filter_query_parameters": [
('token', 'MOCK_TOKEN'),
("token", "MOCK_TOKEN"),
],
}


@pytest.mark.record_http
def test_wsj_gainers_fetcher(credentials=test_credentials):
params = {}
Expand All @@ -26,7 +28,6 @@ def test_wsj_gainers_fetcher(credentials=test_credentials):
assert result is None



@pytest.mark.record_http
def test_wsj_losers_fetcher(credentials=test_credentials):
params = {}
Expand All @@ -36,13 +37,10 @@ def test_wsj_losers_fetcher(credentials=test_credentials):
assert result is None



@pytest.mark.record_http
def test_wsj_active_fetcher(credentials=test_credentials):
params = {}

fetcher = WSJActiveFetcher()
result = fetcher.test(params, credentials)
assert result is None


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


from openbb_provider.abstract.provider import Provider
from openbb_yfinance.models.active import YFActiveFetcher
from openbb_yfinance.models.available_indices import YFinanceAvailableIndicesFetcher
from openbb_yfinance.models.balance_sheet import YFinanceBalanceSheetFetcher
from openbb_yfinance.models.cash_flow import YFinanceCashFlowStatementFetcher
Expand All @@ -10,7 +11,9 @@
from openbb_yfinance.models.forex_historical import YFinanceForexHistoricalFetcher
from openbb_yfinance.models.futures_curve import YFinanceFuturesCurveFetcher
from openbb_yfinance.models.futures_historical import YFinanceFuturesHistoricalFetcher
from openbb_yfinance.models.gainers import YFGainersFetcher
from openbb_yfinance.models.income_statement import YFinanceIncomeStatementFetcher
from openbb_yfinance.models.losers import YFLosersFetcher
from openbb_yfinance.models.major_indices_historical import (
YFinanceMajorIndicesHistoricalFetcher,
)
Expand All @@ -36,5 +39,8 @@
"CashFlowStatement": YFinanceCashFlowStatementFetcher,
"IncomeStatement": YFinanceIncomeStatementFetcher,
"AvailableIndices": YFinanceAvailableIndicesFetcher,
"EquityActive": YFActiveFetcher,
"EquityGainers": YFGainersFetcher,
"EquityLosers": YFLosersFetcher,
},
)
Loading
Loading