tastyware / tastytrade

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

instruments.Option.get_options no working #128

Closed hjnoble3 closed 9 months ago

hjnoble3 commented 9 months ago

I am looking for something similar like these for equity options:

`from tastytrade import instruments

cryptocurrency = instruments.Cryptocurrency.get_cryptocurrencies(session) future_options = instruments.FutureOptionProduct.get_future_option_products(session) `

It looks like the following was suppose to do the desired function but results in error. options = instruments.Option.get_options(session)

'--------------------------------------------------------------------------- JSONDecodeError Traceback (most recent call last) File /usr/local/lib/python3.10/dist-packages/requests/models.py:971, in Response.json(self, kwargs) 970 try: --> 971 return complexjson.loads(self.text, kwargs) 972 except JSONDecodeError as e: 973 # Catch JSON-related errors and raise as requests.JSONDecodeError 974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /usr/local/lib/python3.10/dist-packages/simplejson/init.py:514, in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, use_decimal, allow_nan, **kw) 510 if (cls is None and encoding is None and object_hook is None and 511 parse_int is None and parse_float is None and 512 parse_constant is None and object_pairs_hook is None 513 and not use_decimal and not allow_nan and not kw): --> 514 return _default_decoder.decode(s) 515 if cls is None:

File /usr/local/lib/python3.10/dist-packages/simplejson/decoder.py:386, in JSONDecoder.decode(self, s, _w, _PY3) 385 s = str(s, self.encoding) --> 386 obj, end = self.raw_decode(s) 387 end = _w(s, end).end()

File /usr/local/lib/python3.10/dist-packages/simplejson/decoder.py:416, in JSONDecoder.raw_decode(self, s, idx, _w, _PY3) 415 idx += 3 --> 416 return self.scan_once(s, idx=_w(s, idx).end()) ... 973 # Catch JSON-related errors and raise as requests.JSONDecodeError 974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError --> 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0) '

I have run the corresponding Postman provided by Tasty which also errors:

image

I have reached out to Tasty to see what is happening in Postman about 2 weeks ago and have not heard anything.

Does anyone know a work around?

I ultimately plan to use the information to filter down to underlying I am interested in trading based on things like finances (pulled from yahoo), number of expiration between two dates, and average slippage and open interest per options contract.

Graeme22 commented 9 months ago

I see that in the documentation that passing a list of symbols is optional, though from this is looks like it's required. I think that makes sense though, I mean it's kinda ambiguous what should happen if you don't pass any symbols in... There's hundreds of thousands of options contracts out there! If you call Option.get_options make sure to pass in the symbols you want. Here's the relevant docs: https://tastyworks-api.readthedocs.io/en/latest/tastytrade.html#tastytrade.instruments.Option.get_options

If you're looking for a specific underlying, what you want is probably get_option_chain, which you can read about here: https://tastyworks-api.readthedocs.io/en/latest/tastytrade.html#tastytrade.instruments.get_option_chain

hjnoble3 commented 9 months ago

Thanks for the quick reply.

from tastytrade import instruments options = instruments.Option.get_options(session, ['SPY', 'TSLA', 'LULU']) results in an empty list. So does: options = instruments.Option.get_options(session, 'SPY')

Tasty also replayed today as well and said a symbol is needed or else the GET will timeout.

I tried adding a symbol in Postman and it returns an empty list as well, so it does not seem to be an issue with python. image

Tasty recommended using GET /option-chains/:symbol/nested which is equivalent to instruments.NestedOptionChain.get_chain().

Since instruments.Option.get_options() is functioning as expected in Postman should I close this, or leave it open since I do not know why blank lists are returned in Postman?

Graeme22 commented 9 months ago

Option.get_options is for options symbols, not stock symbols. So something like "AAPL 220617P00150000" instead of "SPY" would work. If you want the options symbols associated with an underlying, use get_option_chain. You can read about symbology here: https://developer.tastytrade.com/#tastytrade-symbology

hjnoble3 commented 9 months ago

That makes sense and works.

Thanks for the help!