Unable to start websocket stream from Binance Futures

Hey guys! Can you help me please? I am trying to start a stream and fetch all its candles data for coin. But I have a problem - nothing happens.

this is my code:

websocket.enableTrace(False)
socket = f’wss://fstream.binance.com/ws/btcusdt_perpetual@continuousKline_1m’
ws = websocket.WebSocketApp(socket,on_message=on_message)
ws.run_forever()

but new message never arrives in on_message method. By the way, can you tell me please, how can I start streams for all active on Binance futures pairs? Is it possible?

Hi,

Are you using one of the Binance Connector libraries from Github? From the code that you’ve provided, it seems that you haven’t provided the entire context which would be useful for us to provide troubleshooting advice.

Take a look at the Python Futures Connector: GitHub - binance/binance-futures-connector-python

Here is some example code using the above library which allows you to combine multiple different streams by adding each stream that you wish to subscribe to to the array:

import time
from binance.websocket.um_futures.websocket_client import UMFuturesWebsocketClient

def message_handler(message):
    print(message)

ws_client = UMFuturesWebsocketClient()
ws_client.start()

# Combine selected streams
ws_client.instant_subscribe(
    stream=['bnbusdt@bookTicker', 'ethusdt@bookTicker'],
    callback=message_handler,
)

time.sleep(10)

print("closing ws connection")
ws_client.stop()