I have this code, and I need to store in a variable the last price, how can i do?
class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def tickPrice(self, reqId, tickType, price, attrib):
if tickType == 2 and reqId == 1:
print('The current ask price is: ', price)
app = IBapi()
app.connect('127.0.0.1', 7497, 123)
#Create contract object
apple_contract = Contract()
apple_contract.symbol = 'AAPL'
apple_contract.secType = 'STK'
apple_contract.exchange = 'SMART'
apple_contract.currency = 'USD'
app.reqMktData(1, apple_contract, '', False, False, [])
I need to save in a variable the current price