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/v4-dividend-calendar: Adds Nasdaq dividend calendar and moves the command out of fundamental_analysis #5672

Merged
merged 12 commits into from
Nov 6, 2023
28 changes: 20 additions & 8 deletions openbb_platform/extensions/stocks/integration/test_stocks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ def test_stocks_fa_balance_growth(params, headers):

@pytest.mark.parametrize(
"params",
[({"start_date": "2023-01-01", "end_date": "2023-06-06"})],
[
({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "fmp"}),
({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "nasdaq"}),
],
)
@pytest.mark.integration
def test_stocks_fa_cal(params, headers):
def test_stocks_calendar_dividend(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/fa/cal?{query_str}"
url = f"http://0.0.0.0:8000/api/v1/stocks/calendar_dividend?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200
Expand Down Expand Up @@ -405,21 +408,30 @@ def test_stocks_fa_ins_own(params, headers):
[
(
{
"provider": "intrinio",
"symbol": "UBER",
"start_date": "2018-01-01",
"symbol": "",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"limit": 100,
"provider": "intrinio",
}
),
(
{
"start_date": "2023-01-01",
"end_date": "2023-11-01",
"status": "priced",
"provider": "nasdaq",
"is_spo": False,
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_ipo(params, headers):
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/fa/ipo?{query_str}"
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
Expand Down
30 changes: 18 additions & 12 deletions openbb_platform/extensions/stocks/integration/test_stocks_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ def test_stocks_fa_balance_growth(params, obb):
@pytest.mark.parametrize(
"params",
[
(
{
"start_date": "2023-01-01",
"end_date": "2023-06-06",
}
),
({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "fmp"}),
({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "nasdaq"}),
],
)
@pytest.mark.integration
def test_stocks_fa_cal(params, obb):
result = obb.stocks.fa.cal(**params)
def test_stocks_calendar_dividend(params, obb):
result = obb.stocks.calendar_dividend(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Expand Down Expand Up @@ -390,17 +386,27 @@ def test_stocks_fa_ins_own(params, obb):
[
(
{
"symbol": "UBER",
"start_date": "2018-01-01",
"symbol": "",
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"limit": 100,
"provider": "intrinio",
}
),
(
{
"start_date": "2023-01-01",
"end_date": "2023-11-01",
"status": "priced",
"provider": "nasdaq",
"is_spo": False,
}
),
],
)
@pytest.mark.integration
def test_stocks_fa_ipo(params, obb):
result = obb.stocks.fa.ins_own(**params)
def test_stocks_calendar_ipo(params, obb):
result = obb.stocks.calendar_ipo(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
Expand Down
22 changes: 0 additions & 22 deletions openbb_platform/extensions/stocks/openbb_stocks/fa/fa_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ def balance_growth(
return OBBject(results=Query(**locals()).execute())


@router.command(model="DividendCalendar")
def cal(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Dividend Calendar. Show Dividend Calendar for a given start and end dates."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="CashFlowStatement")
def cash(
cc: CommandContext,
Expand Down Expand Up @@ -180,17 +169,6 @@ def ins_own(
return OBBject(results=Query(**locals()).execute())


@router.command(model="CalendarIpo")
def ipo(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Upcoming and Historical IPO Calendar."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="KeyMetrics")
def metrics(
cc: CommandContext,
Expand Down
22 changes: 22 additions & 0 deletions openbb_platform/extensions/stocks/openbb_stocks/stocks_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,25 @@ def price_performance(
) -> OBBject[BaseModel]:
"""Price performance as a return, over different periods."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="CalendarIpo")
def calendar_ipo(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Upcoming and Historical IPO Calendar."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="CalendarDividend")
def calendar_dividend(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Upcoming and Historical Dividend Calendar."""
return OBBject(results=Query(**locals()).execute())
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Dividend Calendar data model."""


from datetime import date as dateType
from typing import Optional

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


class DividendCalendarQueryParams(QueryParams):
"""Dividend Calendar Query."""

start_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("start_date", "")
)
end_date: Optional[dateType] = Field(
default=None, description=QUERY_DESCRIPTIONS.get("end_date", "")
)


class DividendCalendarData(Data):
"""Dividend Calendar Data."""

date: dateType = Field(
description=DATA_DESCRIPTIONS.get("date", "") + " (Ex-Dividend)"
)
symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
name: Optional[str] = Field(description="Name of the entity.", default=None)
record_date: Optional[dateType] = Field(
default=None,
description="The record date of ownership for eligibility.",
)
payment_date: Optional[dateType] = Field(
default=None,
description="The payment date of the dividend.",
)
declaration_date: Optional[dateType] = Field(
default=None,
description="Declaration date of the dividend.",
)
amount: Optional[float] = Field(
default=None, description="Dividend amount, per-share."
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def end_date_validate(cls, v): # pylint: disable=E0213
class CalendarIpoData(Data):
"""IPO Calendar Data."""

symbol: str = Field(
symbol: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
ipo_date: dateType = Field(
ipo_date: Optional[dateType] = Field(
description="The date of the IPO, when the stock first trades on a major exchange.",
default=None,
)
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions openbb_platform/providers/fmp/openbb_fmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from openbb_fmp.models.available_indices import FMPAvailableIndicesFetcher
from openbb_fmp.models.balance_sheet import FMPBalanceSheetFetcher
from openbb_fmp.models.balance_sheet_growth import FMPBalanceSheetGrowthFetcher
from openbb_fmp.models.calendar_dividend import FMPDividendCalendarFetcher
from openbb_fmp.models.cash_flow import FMPCashFlowStatementFetcher
from openbb_fmp.models.cash_flow_growth import FMPCashFlowStatementGrowthFetcher
from openbb_fmp.models.company_filings import FMPCompanyFilingsFetcher
from openbb_fmp.models.company_overview import FMPCompanyOverviewFetcher
from openbb_fmp.models.crypto_historical import FMPCryptoHistoricalFetcher
from openbb_fmp.models.dividend_calendar import FMPDividendCalendarFetcher
from openbb_fmp.models.earnings_calendar import FMPEarningsCalendarFetcher
from openbb_fmp.models.earnings_call_transcript import FMPEarningsCallTranscriptFetcher
from openbb_fmp.models.economic_calendar import FMPEconomicCalendarFetcher
Expand Down Expand Up @@ -108,7 +108,7 @@
"AvailableIndices": FMPAvailableIndicesFetcher,
"RiskPremium": FMPRiskPremiumFetcher,
"MajorIndicesConstituents": FMPMajorIndicesConstituentsFetcher,
"DividendCalendar": FMPDividendCalendarFetcher,
"CalendarDividend": FMPDividendCalendarFetcher,
"StockQuote": FMPStockQuoteFetcher,
"FinancialRatios": FMPFinancialRatiosFetcher,
"PricePerformance": FMPPricePerformanceFetcher,
Expand Down
Loading
Loading