Futures market websockets work differently

I use this code for binance websocket:
import websocket
def on_message(ws, message):
print(message)

def on_error(ws, error):
    print(error)

def on_close(ws):
    print("### closed ###")

def on_open(ws):
    print("### connected ###")

if __name__ == "__main__":
    ws = websocket.WebSocketApp("wss://stream.binance.com/ws/btcusdt@aggTrade/etcusdt@aggTrade/ethusdt@aggTrade/ltcusdt@aggTrade/bchusdt@aggTrade/xrpusdt@aggTrade/eosusdt@aggTrade",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever()

It works good for spot market. Hovewer when i change to futures it only shows β€œ### connected ###” (wss://stream.binance.com β€”> wss://fstream.binance.com). What could be the problem?

please have a try with just one stream

wss://fstream.binance.com/ws/btcusdt@aggTrade

this works fine for me.

1 Like

Please use wss://fstream.binance.com/stream?streams=btcusdt@aggTrade/etcusdt@aggTrade/…/… if you want multiple data streams

1 Like

Changing code to stream?streams=… worked for me. Hovewer the last time i used code(/ws/) in september and it worked.

Please stick with the api document. As per the doc, you need to use β€œstream=” if you want multiple streams. Anything not in the doc cannot be guaranteed to work.