tastytrade/streaming_option_chain_example.py

27 lines
1.0 KiB
Python

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
This example does not currently work.
The DXLink connection does not currently support options data.
Refer to the comments on this video: https://www.youtube.com/watch?v=qHL4Jy6yIC8
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
from datetime import datetime
from dotenv import load_dotenv
from os import getenv
from tastytrade import Tastytrade
load_dotenv()
account = getenv("TASTYTRADE_ACCOUNT")
username = getenv("TASTYTRADE_USERNAME")
password = getenv("TASTYTRADE_PASSWORD")
client = Tastytrade(username, password)
client.login()
current_date = datetime.now().strftime('%y%m%d')
symbol_prefix = f'.SPXW{current_date}'
option_chain_data = client.get_option_chain_compact('SPX')['data']['items'][0]
streamer_symbols = option_chain_data['streamer-symbols']
zero_dte_symbols = [symbol for symbol in streamer_symbols if symbol.startswith(symbol_prefix)]
client.start_streaming(zero_dte_symbols)