} ''' Option chain possible fields symbol: contractType: strikeCount: includeQuotes: strategy: interval strike range fromDate toDate volatility underlyingPrice interestRate daysToExpiration expMonth optionType ''' # Get Option Chains option_chains = TDSession.get_options_chain(option_chain = opt_chain) for key, value in option_chains.items(): with open('option_chain.json', 'w') as outfile: json.dump(option_chains, outfile, indent=2)
if TD['symbol'] == '': TD['symbol'] = input('\n\nPlease input the symbol\n\n') # Create a new session, a local credentials file is required. TDSession = TDClient(client_id=TD['client_id'], redirect_uri='http://localhost', credentials_path=os.path.join( os.path.dirname(os.path.abspath(__file__)), 'state.json')) # Login to TDAmertrade to authenticate this app TDSession.login() # Get the options chain option_chain = TDSession.get_options_chain( option_chain={ # Documentation # https://developer.tdameritrade.com/option-chains/apis/get/marketdata/chains 'symbol': TD['symbol'], 'contractType': 'CALL', 'strikeCount': 5, 'range': 'OTM', 'fromDate': TD['fromDate'], 'toDate': TD['toDate'], }) # Print returned json to the screen print('\n') pprint.pprint(option_chain) input('\n\nPress Enter to close\n\n')