0

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

BTT
  • 17
  • 4
  • Rather than trying to return data via a return statement I can append the returned list to self.data then access the self.data. self.data.append(contractDetails.contract.primaryExchange) then contract.primaryExchange = app.data[0] – BTT Dec 08 '22 at 10:52

0 Answers0