It looks like it only works on stocks / ETF's. When trying to pull indices like 'SPX' or 'XSP' this throws an error.
My code:
from tastytrade.instruments import NestedOptionChain
n_chain = NestedOptionChain.get_chain(session, 'SPX')
print(n_chain.expirations[0].strikes[0])
## Does not work on SPX
The error message:
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[43], line 3
1 from tastytrade.instruments import NestedOptionChain
----> 3 n_chain = NestedOptionChain.get_chain(session, 'SPX')
4 print(n_chain.expirations[0].strikes[0])
6 ## Does not work on SPX
File [~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/tastytrade/instruments.py:547](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/tastytrade/instruments.py:547), in NestedOptionChain.get_chain(cls, session, symbol)
[543](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/tastytrade/instruments.py:543) validate_response(response)
[545](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/tastytrade/instruments.py:545) data = response.json()['data']['items'][0]
--> [547](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/tastytrade/instruments.py:547) return cls(**data)
File [~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:341](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:341), in BaseModel.__init__(__pydantic_self__, **data)
[339](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:339) values, fields_set, validation_error = validate_model(__pydantic_self__.__class__, data)
[340](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:340) if validation_error:
--> [341](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:341) raise validation_error
[342](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:342) try:
[343](https://file+.vscode-resource.vscode-cdn.net/Users/crg/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/~/VSCode_Python/VENVS/python_3_12/tasty_api/.venv/lib/python3.12/site-packages/pydantic/main.py:343) object_setattr(__pydantic_self__, '__dict__', values)
ValidationError: 2 validation errors for NestedOptionChain
deliverables -> 0 -> symbol
field required (type=value_error.missing)
deliverables -> 0 -> instrument-type
field required (type=value_error.missing)
tried another example from the documentation:
Options chains
It looks like it only works on stocks / ETF's. When trying to pull indices like 'SPX' or 'XSP' this throws an error.
My code:
The error message:
Pulling 'SPY', this works like a charm.
Did not find any documentation for Indices.