Assigning method output to a variable in python

62 views Asked by At

the below code will output the last price of a stock continuously until stopped as shown on the console.

What I would like to do is output the price in a tkinter label, but my code would not do it.

enter image description here

from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract

lass 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)

def run_loop():
    app.run()

app = IBapi()
app.connect('127.0.0.1', 4002, 123)



#Define the contract
stock_contract = Contract()
stock_contract.symbol = 'AMZN'
stock_contract.secType = 'STK'
stock_contract.exchange = 'SMART'
stock_contract.currency = 'USD'

#Request Market Data
app.reqMktData(1, stock_contract, '', False, False, [])

I tried modifying it like below so I can show it on a label but it does not work. When trying to print out data I get error NONE

data = app.reqMktData(1, stock_contract, '', False, False, [])
labellastprice_ticker5.configure(text=data)

Surely I am sure I am missing something fundamental here.

0

There are 0 answers