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

Intrinio realtime (delayed) options #6931

Merged
merged 38 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e84379c
remove ultima + althub
jmaslek Feb 27, 2024
8b68f23
move twitter keys
jmaslek Feb 27, 2024
6a8a1ea
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Feb 29, 2024
21cc561
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 11, 2024
9f9cba3
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 12, 2024
2914c7e
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 13, 2024
61400fc
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 14, 2024
19c6371
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 14, 2024
8651771
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 14, 2024
5d6344c
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 14, 2024
853e3fe
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Mar 15, 2024
25536e3
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek May 2, 2024
fea3821
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek May 9, 2024
9d4e054
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek May 14, 2024
926d344
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek May 18, 2024
92f3da4
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek May 31, 2024
ffdf8a6
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 3, 2024
21ba826
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 3, 2024
a8b8a14
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 11, 2024
13b870e
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 12, 2024
61576f4
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 13, 2024
67cefd3
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 14, 2024
2b1a833
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jun 18, 2024
b3aed17
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jul 8, 2024
81f5870
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jul 12, 2024
7ad78c9
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Jul 24, 2024
62976c3
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Aug 7, 2024
fd4d187
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Aug 21, 2024
bd6646f
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Sep 30, 2024
7ef0610
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Oct 3, 2024
79f95a7
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Oct 8, 2024
1e712b1
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Oct 11, 2024
1e8f636
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Oct 15, 2024
06172ea
Merge branch 'develop' of https://github.com/OpenBB-finance/OpenBBTer…
jmaslek Nov 4, 2024
97ba050
Small edits to allow realtime/delayed intrinio options
jmaslek Nov 4, 2024
792bb58
update tests
deeleeramone Nov 4, 2024
839ad28
static files and fix date validator
deeleeramone Nov 4, 2024
90735e6
expose the data collecting tasks to Unauthorized Error
deeleeramone Nov 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def headers():
"model": "black_scholes",
"show_extended_price": False,
"include_related_symbols": False,
"delay": "delayed",
}
),
({"provider": "cboe", "symbol": "AAPL", "use_cache": False}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def obb(pytestconfig):
"model": "black_scholes",
"show_extended_price": False,
"include_related_symbols": False,
"delay": "delayed",
}
),
({"provider": "cboe", "symbol": "AAPL", "use_cache": False}),
Expand Down
17 changes: 16 additions & 1 deletion openbb_platform/openbb/assets/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,18 @@
}
],
"intrinio": [
{
"name": "delay",
"type": "Literal['eod', 'realtime', 'delayed']",
"description": "Whether to return delayed, realtime, or eod data.",
"default": "eod",
"optional": true,
"choices": [
"eod",
"realtime",
"delayed"
]
},
{
"name": "date",
"type": "Union[date, str]",
Expand Down Expand Up @@ -1875,7 +1887,10 @@
"description": "The pricing model to use for options chains data, default is 'black_scholes'. Parameter is ignored when a date is supplied.",
"default": "black_scholes",
"optional": true,
"choices": null
"choices": [
"black_scholes",
"bjerk"
]
},
{
"name": "show_extended_price",
Expand Down
28 changes: 28 additions & 0 deletions openbb_platform/openbb/package/derivatives_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def chains(
Symbol to get data for.
provider : Optional[Literal['intrinio', 'yfinance']]
The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: intrinio, yfinance.
delay : Literal['eod', 'realtime', 'delayed']
Whether to return delayed, realtime, or eod data. (provider: intrinio)
date : Optional[datetime.date]
The end-of-day date for options chains data. (provider: intrinio)
option_type : Optional[Literal['call', 'put']]
Expand Down Expand Up @@ -211,6 +213,32 @@ def chains(
"symbol": symbol,
},
extra_params=kwargs,
info={
"delay": {
"intrinio": {
"multiple_items_allowed": False,
"choices": ["eod", "realtime", "delayed"],
}
},
"option_type": {
"intrinio": {
"multiple_items_allowed": False,
"choices": ["call", "put"],
}
},
"moneyness": {
"intrinio": {
"multiple_items_allowed": False,
"choices": ["otm", "itm", "all"],
}
},
"model": {
"intrinio": {
"multiple_items_allowed": False,
"choices": ["black_scholes", "bjerk"],
}
},
},
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from openbb_core.provider.utils.errors import OpenBBError
from openbb_intrinio.models.equity_historical import IntrinioEquityHistoricalFetcher
from openbb_intrinio.models.index_historical import IntrinioIndexHistoricalFetcher
from pydantic import Field, field_validator
from pydantic import Field, field_validator, model_validator


class IntrinioOptionsChainsQueryParams(OptionsChainsQueryParams):
Expand All @@ -34,20 +34,40 @@ class IntrinioOptionsChainsQueryParams(OptionsChainsQueryParams):
"oi_lt": "open_interest_less_than",
"option_type": "type",
}
__json_schema_extra__ = {
"moneyness": {
"multiple_items_allowed": False,
"choices": ["otm", "itm", "all"],
},
"delay": {
"multiple_items_allowed": False,
"choices": ["eod", "realtime", "delayed"],
},
"option_type": {
"multiple_items_allowed": False,
"choices": ["call", "put"],
},
"model": {
"multiple_items_allowed": False,
"choices": ["black_scholes", "bjerk"],
},
}

delay: Literal["eod", "realtime", "delayed"] = Field(
description="Whether to return delayed, realtime, or eod data.",
default="eod",
)
date: Optional[dateType] = Field(
default=None, description="The end-of-day date for options chains data."
)
option_type: Optional[Literal["call", "put"]] = Field(
default=None,
description="The option type, call or put, 'None' is both (default).",
json_schema_extra={"choices": ["call", "put"]},
)
moneyness: Literal["otm", "itm", "all"] = Field(
default="all",
description="Return only contracts that are in or out of the money, default is 'all'."
+ " Parameter is ignored when a date is supplied.",
json_schema_extra={"choices": ["otm", "itm", "all"]},
)
strike_gt: Optional[int] = Field(
default=None,
Expand Down Expand Up @@ -95,6 +115,14 @@ class IntrinioOptionsChainsQueryParams(OptionsChainsQueryParams):
+ " default is False.",
)

@model_validator(mode="after")
@classmethod
def date_not_allowed_with_realtime(cls, values: Any) -> Any:
"""Return an error if the date is supplied when delay is realtime."""
if values.delay != "eod" and values.date:
warn("Date is ignored when accessing realtime or delayed data.")
return values


class IntrinioOptionsChainsData(OptionsChainsData):
"""Intrinio Options Chains Data."""
Expand Down Expand Up @@ -133,18 +161,25 @@ def _date_validate(cls, v):
from dateutil import parser
from pytz import timezone

if isinstance(v, str):
dt = parser.parse(v)
dt = dt.replace(tzinfo=timezone("UTC"))
dt = dt.astimezone(timezone("America/New_York"))
return dt.replace(microsecond=0)
return v if v else None
if not v:
return None
new_v: list = []
for item in v:
if item:
dt = parser.parse(item)
dt = dt.replace(tzinfo=timezone("UTC"))
dt = dt.astimezone(timezone("America/New_York"))
new_v.append(dt.replace(microsecond=0))
else:
new_v.append(None)

return new_v

@field_validator("volume", "open_interest", mode="before", check_fields=False)
@classmethod
def _volume_oi_validate(cls, v):
"""Return the volume as an integer."""
return 0 if v is None else v
return [0 if item is None else item for item in v]


class IntrinioOptionsChainsFetcher(
Expand All @@ -167,11 +202,14 @@ async def aextract_data(
# pylint: disable=import-outside-toplevel
from datetime import timedelta # noqa
from openbb_core.provider.utils.helpers import (
ClientResponse,
amake_requests,
get_querystring,
)
from openbb_intrinio.utils.helpers import get_data_many, get_weekday
from openbb_intrinio.utils.helpers import (
get_data_many,
get_weekday,
response_callback,
)

api_key = credentials.get("intrinio_api_key") if credentials else ""

Expand All @@ -190,8 +228,10 @@ async def get_urls(date: str) -> List[str]:
"%Y-%m-%d"
)
url = (
f"{base_url}/expirations/{query.symbol}/eod?"
f"after={date}&api_key={api_key}"
f"{base_url}/expirations/{query.symbol}/"
f"{'eod' if query.delay == 'eod' else 'realtime'}?"
f"{'after=' + date + '&' if query.delay == 'eod' else 'source=' + query.delay + '&'}"
f"api_key={api_key}"
)
expirations = await get_data_many(url, "expirations", **kwargs)

Expand Down Expand Up @@ -231,9 +271,9 @@ def generate_url(expiration) -> str:

return [generate_url(expiration) for expiration in expirations]

async def callback(response: ClientResponse, _: Any) -> List:
async def callback(response, _) -> list:
"""Return the response."""
response_data = await response.json()
response_data = await response_callback(response, _)
return response_data.get("chain", []) # type: ignore

results = await amake_requests(
Expand Down
Loading
Loading