Вот такого вида данные в сокете, не знаю как достать эти значения:
"s":"BTCUSDT"
"p":"51654.30"
Потому что не вижу переменную у словаря...
Нужно потом эти значения сравнить в потоке, например:
if "p" > 51500:
print("Монета больше 51500")
++Rcv raw: b'\x81~\x00\x94{"e":"aggTrade","E":1708502035434,"a":2027020267,"s":"BTCUSDT","p":"51654.30","q":"0.028","f":4617647950,"l":4617647950,"T":1708502035281,"m":false}'
++Rcv decoded: fin=1 opcode=1 data=b'{"e":"aggTrade","E":1708502035434,"a":2027020267,"s":"BTCUSDT","p":"51654.30","q":"0.028","f":4617647950,"l":4617647950,"T":1708502035281,"m":false}'
{"e":"aggTrade","E":1708502035434,"a":2027020267,"s":"BTCUSDT","p":"51654.30","q":"0.028","f":4617647950,"l":4617647950,"T":1708502035281,"m":false}
код самой мини-вебсокетной програмки
import websocket
import _thread
import time
import rel
def on_message(ws, message):
print(message)
def on_error(ws, error):
print(error)
def on_close(ws, close_status_code, close_msg):
print("### closed ###")
def on_open(ws):
print("Opened connection")
if __name__ == "__main__":
websocket.enableTrace(True)
ws = websocket.WebSocketApp("wss://fstream.binance.com/ws/btcusdt@aggTrade",
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever(dispatcher=rel, reconnect=5) # Set dispatcher to automatic reconnection, 5 second reconnect delay if connection closed unexpectedly
rel.signal(2, rel.abort) # Keyboard Interrupt
rel.dispatch()