'how to stop run_forever and do other jobs, then continue running in python websocket?
"my question is how to stop websocket running when the bid_sirt has changed, I want to make another calculation and then come back restart websocket"
bid_sirts = [1,1]
def ws_message(ws, message):
global bid_sirt
bid_sirt= json.loads(message)["result"]["bids"][0]
bid_sirts.append(bid_sirt)
def ws_open(ws):
ws.send(json.dumps({
"time": int(time.time()),
"channel": "spot.order_book",
"event": "subscribe", # "unsubscribe" for unsubscription
"payload": ["BTC_USDT", "10", "100ms"]
}))
def ws_close(ws):
print("ws closed")
def ws_orderbook():
ws = websocket.WebSocketApp("wss://api.gateio.ws/ws/v4/", on_open=ws_open, on_message=ws_message,on_close=ws_close)
ws.keep_running = False
if bid_sirts[-2] != bid_sirts[-1]:
ws.keep_running = True
print("ws closed")`enter code here`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
