tastyware / tastytrade

An unofficial, sync/async Python SDK for Tastytrade!
https://tastyworks-api.rtfd.io
MIT License
126 stars 43 forks source link

Option.get_option 404 response #81

Closed alexonab closed 1 year ago

alexonab commented 1 year ago

Describe the bug Option.get_option returns a 404.

How to reproduce

>>> from tastytrade import ProductionSession as Session
>>> from tastytrade.instruments import get_option_chain, Option
>>> session = Session(username, password)
>>> chain = get_option_chain(session, 'SPY')
>>> subs_list = [chain[date(2023, 7, 28)][0].streamer_symbol]
>>> subs_list[0]
'.SPY230728C275'
>>> Option.get_option(session, subs_list[0])
<Response [404]>
Quenos commented 1 year ago

You should either create a ProductionSession or a CertificationSession

from tastytrade import ProductionSession, CertificationSession e.g. session = CertificationSession(username, password)

alexonab commented 1 year ago

You should either create a ProductionSession or a CertificationSession

from tastytrade import ProductionSession, CertificationSession e.g. session = CertificationSession(username, password)

I imported ProductionSession as Session.

Quenos commented 1 year ago

I can't reproduce

>>> session = ProductionSession(user, password)
>>> chain = get_option_chain(session, 'SPY')
>>> subs_list = [chain[date(2023, 7, 28)][0].streamer_symbol]
>>> print(subs_list)
['.SPY230728C275']
alexonab commented 1 year ago

@Quenos

The error occurs calling Option.get_option.

Option.get_option(session, subs_list[0])

Quenos commented 1 year ago

I see. Bet get_option has a different interface:

   def get_option(
        cls,
        session: Session,
        symbol: str,
        active: Optional[bool] = None
    ) -> 'Option'
alexonab commented 1 year ago

I figured out what I was doing wrong.

When filtering the option chain, I was returning streamer_symbol and not symbol. These have different formats.

>>> subs_list = [chain[date(2023, 7, 28)][0]]
>>> subs_list[0].streamer_symbol
'.SPY230728C275'
>>> subs_list[0].symbol
'SPY   230728C00275000'
>>> Option.get_option(session, subs_list[0].symbol)
<OptionType.CALL: 'C'>, option_chain_type='Standard', expiration_type='Weekly', settlement_type='PM', stops_trading_at=datetime.datetime(2023, 7, 28, 20, 15, tzinfo=datetime.timezone.utc), market_time_instrument_collection='Cash Settled Equity Option', days_to_expiration=1, expires_at=datetime.datetime(2023, 7, 28, 20, 15, tzinfo=datetime.timezone.utc), is_closing_only=False, listed_market=None, halted_at=None, old_security_number=None, streamer_symbol='.SPY230728C275')
Graeme22 commented 1 year ago

Glad you figured it out! So yeah, the streamer symbol is just for use with the streamer.