tastytrade/streaming_option_chain_example.py

21 lines
669 B
Python
Raw Normal View History

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.stream_quotes(zero_dte_symbols)