Skip to content

Commit

Permalink
Merge pull request #13 from OpenBB-finance/feature/openbb-sdk-v4
Browse files Browse the repository at this point in the history
Feature/openbb sdk v4
  • Loading branch information
AdiSai authored Nov 8, 2023
2 parents 13a19aa + e5e10d3 commit 99f8890
Show file tree
Hide file tree
Showing 22 changed files with 1,475 additions and 1,566 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ def test_economy_gdpforecast(params, headers):
(
{
"provider": "nasdaq",
"start_date": "2023-05-01",
"end_date": "2023-05-10",
"country": "spain,france",
"start_date": "2023-10-24",
"end_date": "2023-11-03",
"country": "united_states,japan",
}
),
(
Expand All @@ -508,7 +508,7 @@ def test_economy_gdpforecast(params, headers):
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"country": "mexico,sweden",
"importance": "low",
"importance": "Low",
"group": "gdp",
}
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ def test_economy_gdpforecast(params, obb):
{
"provider": "nasdaq",
"start_date": "2023-10-24",
"end_date": "2023-10-27",
"country": "spain,france",
"end_date": "2023-11-03",
"country": "united_states,japan",
}
),
(
Expand All @@ -447,7 +447,7 @@ def test_economy_gdpforecast(params, obb):
"start_date": "2023-01-01",
"end_date": "2023-06-06",
"country": "mexico,sweden",
"importance": "medium",
"importance": "Medium",
"group": "gdp",
}
),
Expand Down
41 changes: 40 additions & 1 deletion openbb_platform/extensions/stocks/integration/test_stocks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,24 @@ def test_stocks_options_chains(params, headers):
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
({"symbol": None, "source": "delayed", "provider": "intrinio"}),
({"symbol": "PLTR", "source": "delayed", "provider": "intrinio"}),
],
)
@pytest.mark.integration
def test_stocks_options_unusual(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/options/unusual?{query_str}"
result = requests.get(url, headers=headers, timeout=10)
assert isinstance(result, requests.Response)
assert result.status_code == 200


@pytest.mark.parametrize(
"params",
[
Expand Down Expand Up @@ -1181,7 +1199,28 @@ def test_stocks_disc_upcoming_release_days(params, headers):

@pytest.mark.parametrize(
"params",
[({"pages": 1, "limit": 5, "today": True, "provider": "fmp"})],
[
(
{
"start_date": None,
"end_date": None,
"limit": 10,
"form_type": None,
"is_done": None,
"provider": "fmp",
}
),
(
{
"start_date": "2023-11-06",
"end_date": "2023-11-07",
"limit": 50,
"form_type": "10-Q",
"is_done": "true",
"provider": "fmp",
}
),
],
)
@pytest.mark.integration
def test_stocks_disc_filings(params, headers):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,21 @@ def test_stocks_options_chains(params, obb):
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[
({"symbol": None, "source": "delayed", "provider": "intrinio"}),
({"symbol": "PLTR", "source": "delayed", "provider": "intrinio"}),
],
)
@pytest.mark.integration
def test_stocks_options_unusual(params, obb):
result = obb.stocks.options.usual(**params)
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0


@pytest.mark.parametrize(
"params",
[
Expand Down Expand Up @@ -1109,7 +1124,28 @@ def test_stocks_disc_upcoming_release_days(params, obb):

@pytest.mark.parametrize(
"params",
[({"pages": 1, "limit": 5, "today": True})],
[
(
{
"start_date": None,
"end_date": None,
"limit": 10,
"form_type": None,
"is_done": None,
"provider": "fmp",
}
),
(
{
"start_date": "2023-11-06",
"end_date": "2023-11-07",
"limit": 50,
"form_type": "10-Q",
"is_done": "true",
"provider": "fmp",
}
),
],
)
@pytest.mark.integration
def test_stocks_disc_filings(params, obb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ def chains(
) -> OBBject[BaseModel]:
"""Get the complete options chain for a ticker."""
return OBBject(results=Query(**locals()).execute())


@router.command(model="OptionsUnusual")
def unusual(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
extra_params: ExtraParams,
) -> OBBject[BaseModel]:
"""Get the complete options chain for a ticker."""
return OBBject(results=Query(**locals()).execute())
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
class EtfCountriesData(Data):
"""ETF Countries Data."""

country: str = Field(description="The country of the exposure.")
weight: float = Field(
description="Exposure of the ETF to the country in normalized percentage points."
country: str = Field(
description="The country of the exposure. Corresponding values are normalized percentage points."
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Filings Data Model."""

from datetime import date as dateType
from datetime import (
date as dateType,
datetime,
)
from typing import Optional

from pydantic import Field, NonNegativeInt
Expand All @@ -13,35 +16,40 @@
class FilingsQueryParams(QueryParams):
"""Filings query."""

pages: NonNegativeInt = Field(
default=1,
description="The range of most-recent pages to get entries from (1000 per page, max 30 pages)",
start_date: Optional[dateType] = Field(
default=None,
description=QUERY_DESCRIPTIONS["start_date"],
)
limit: NonNegativeInt = Field(
default=5, description=QUERY_DESCRIPTIONS.get("limit", "")
end_date: Optional[dateType] = Field(
default=None,
description=QUERY_DESCRIPTIONS["end_date"],
)
form_type: Optional[str] = Field(
default=None,
description="Fuzzy filter by form type. E.g. 10-K, 10, 8, 6-K, etc.",
)
today: bool = Field(
default=False,
description="Show all from today",
limit: NonNegativeInt = Field(
default=100, description=QUERY_DESCRIPTIONS.get("limit", "")
)


class FilingsData(Data):
"""Filings data."""

symbol: str = Field(
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
title: str = Field(
description="The title of the filing",
timestamp: datetime = Field(
description="The timestamp from when the filing was accepted.",
)
date: dateType = Field(
description=DATA_DESCRIPTIONS.get("date", ""),
symbol: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("symbol", ""),
)
url: Optional[str] = Field(description="The URL of the filing", default=None)
cik: str = Field(
description="The CIK of the filing",
)
title: str = Field(
description="The title of the filing",
)
form_type: str = Field(
description="The form type of the filing",
)
url: Optional[str] = Field(description="The URL of the filing", default=None)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Unusual Options data model."""

from typing import Optional

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, QUERY_DESCRIPTIONS


class OptionsUnusualQueryParams(QueryParams):
"""Unusual Options Query Params"""

symbol: Optional[str] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("symbol", "") + " (the underlying symbol)",
)

@field_validator("symbol", mode="before", check_fields=False)
def upper_symbol(cls, v: str):
"""Convert symbol to uppercase."""
return v.upper() if v else None


class OptionsUnusualData(Data):
"""Unusual Options Data."""

underlying_symbol: Optional[str] = Field(
description=DATA_DESCRIPTIONS.get("symbol", "") + " (the underlying symbol)",
default=None,
)
contract_symbol: str = Field(description="Contract symbol for the option.")
Loading

0 comments on commit 99f8890

Please sign in to comment.