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

[FeatureRequest] Options Chain Data missing strike/expiration #515

Open
1 task done
Brett55 opened this issue Oct 6, 2024 · 3 comments
Open
1 task done

[FeatureRequest] Options Chain Data missing strike/expiration #515

Brett55 opened this issue Oct 6, 2024 · 3 comments

Comments

@Brett55
Copy link

Brett55 commented Oct 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe.

The options chain data needs strike/expiration, otherwise I have to query a separate endpoint

Describe the solution you'd like.

include strike/expiration

Describe an alternate solution.

include strike/expiration

Anything else? (Additional Context)

No response

@hiohiohio
Copy link
Contributor

@Brett55 thank you for the request. I have routed this feature request to related teams.

@hiohiohio hiohiohio changed the title Options Chain Data missing strike/expiration Feature request: Options Chain Data missing strike/expiration Oct 7, 2024
@hiohiohio hiohiohio changed the title Feature request: Options Chain Data missing strike/expiration [FeatureRequest] Options Chain Data missing strike/expiration Oct 7, 2024
@umitanuki
Copy link

In fact, the symbol name tells the attributes of the options. So, I would rather vote to add a helper function in SDK than adding payloads to the API. Here is the python snippet recently posted in the slack community.

from datetime import datetime

s = "AAPL240906C00227500"
expiration_date = datetime(
    year=2000 + int(s[-15:-13]),
    month=int(s[-13:-11]),
    day=int(s[-11:-9])
)

@Brett55
Copy link
Author

Brett55 commented Oct 7, 2024

Using other market data providers, they do add the strike and expiration as fields in the payload. These 2 fields are part of the options chain. I think its safer to use a regex if thats what we have to do.

def parse_option_symbol(option_symbol):
    # Use a regular expression to extract the different parts of the symbol
    match = re.match(r"([A-Za-z]{1,4})(\d{6})([CP])(\d{8})", option_symbol)

    if not match:
        raise ValueError("Invalid option symbol format")

    # Extract components from the regular expression match
    underlying = match.group(1)  # The stock symbol (1 to 4 letters)
    expiration = match.group(2)  # 6 characters for expiration date (YYMMDD)
    option_type = match.group(3)  # 1 character for option type ('C' or 'P')
    strike_price_raw = match.group(4)  # 8 characters for the strike price

    # Parse expiration date
    expiration_year = "20" + expiration[:2]  # First 2 digits for year (e.g., '24' -> 2024)
    expiration_month = expiration[2:4]  # Next 2 digits for month
    expiration_day = expiration[4:]  # Last 2 digits for day
    expiration_date = f"{expiration_year}-{expiration_month}-{expiration_day}"  # Format as YYYY-MM-DD

    # Parse strike price (convert from 8-character format)
    strike_price = int(strike_price_raw) / 1000  # Divide by 1000 to get the correct strike price

    # Determine option type
    option_type_full = "Put" if option_type == 'P' else "Call"

    return {
        "underlying": underlying,
        "expiration_date": expiration_date,
        "option_type": option_type_full,
        "strike_price": strike_price
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants