I am trying to return contractDetails.contract.primaryExchange to my contract object. I am isolating the string without problems but I am unable to se it outside of the definition.
def contractDetails(self, reqId, contractDetails):
print("redID: {}, contract:{}".format(reqId,contractDetails.contract.primaryExchange))
return (contractDetails.contract.primaryExchange)
.) .
api_thread = threading.Thread(target=run_loop, daemon=True)
api_thread.start()
time.sleep(1) #Sleep interval to allow time for connection to server
#Create contract object
contract = Contract()
contract.symbol = 'CORN'
contract.secType = 'STK'
contract.exchange = 'SMART'
contract.primaryExchange = ''
contract.currency = 'USD'
contract.primaryExchange = app.reqContractDetails(99, contract)
print(contract)
time.sleep(1) #sleep to allow enough time for data to be returned
print(contract)
What am I not understanding or doing wrong?
Thanks in advance