I have been working with binance websocket. Worked well if the start/stop command is in the main programm. Now I wanted to start and stop the socket through a GUI. So I placed the start/stop command in a function each. But it doesn't work. Just no reaction while calling the function. Any idea what's the problem?
Here the relevant parts of my code (I am quite new to python, any hints to this code are welcome):
def start_websocket(conn_key):
bm.start()
def stop_websocket(conn_key):
bm.close()
def process_message(msg):
currentValues['text']= msg['p']
# --- main ---
PUBLIC = '************************'
SECRET = '************************'
client = Client(api_key=PUBLIC, api_secret=SECRET)
bm = BinanceSocketManager(client)
conn_key = bm.start_trade_socket('BNBBTC', process_message)
# create main window and set its title
root = tk.Tk()
root.title('Websocket')
# create variable for displayed time and use it with Label
label = tk.Label(root)
label.grid(column=5, row=0)
#root.geometry('500x500')
bt_start_socket = tk.Button(root, text="Start Websocket", command=start_websocket(conn_key))
bt_start_socket.grid (column=1, row=1)
bt_stop_socket = tk.Button(root, text="Sop Websocket", command=stop_websocket(conn_key))
bt_stop_socket.grid (column=1, row=10)