Websockets market data Live subscription - bad request


I’m trying to Live Subscribe to two market data streams via websockets - this is running into some bother, what I’m trying to figure out is what I am supposed to be sending.

as the websocket.connect request and then sending
’{“method”: “SUBSCRIBE”, “params”: “btcusdt@miniTicker” , “ethusdt@miniTicker”], “id”: 123}'
as a json string results in a 400 Bad Request response .

  • If I try to connect to just 1 stream using ‘wss://stream.binance.com:9443/ws/btcusdt@miniTicker’ as the websocket.connect request, that works just fine.
  • Using ‘wss://stream.binance.com:9443/stream?streams=btcusdt@miniTicker/ethusdt@miniTicker’ in the websocket.connect request also results in 400 Bad Request.

What am I supposed to be sending? I’ve included the code below for reference.
Help appreciated as I’ve run out of things to try but must be getting close. Thanks!

CODE (uri and params are copied from the Binance-docs website)
url = ‘wss://stream.binance.com:9443’
params ={
“method”: “SUBSCRIBE”,
“id”: 123

async def subscribe():
async with websockets.connect(url) as ws: #connection request with base uri
await ws.send(json.dumps(params)) # send json payload
reply = (await ws.recv())

asyncio.run (subscribe())

is correct for subscribing.

Thanks for confirming Dino.

Sending the full string (‘wss://stream.binance.com:9443/stream?streams=btcusdt@miniTicker/ethusdt@miniTicker’) as the connect request now works - I’m not sure why it works this time around as I’m sure I already tried that (I must have made a typo somewhere).

What I do still like to understand is how to connect with params section - could you help with that or should I start a new topic?
I’m sending:
wss://stream.binance.com:9443/ {“method”: “SUBSCRIBE”, “params”: [“btcusdt@miniTicker”, “ethusdt@miniTicker”], “id”:1}

Getting a 400 Bad Request.

Thanks again!

I think I figured out the params question in the meantime - or at least find a workaround. I wanted to share for others to reference:

  • wss://stream.binance.com:9443/ in itself is not enough to open the wss connection (at least i couldn’t get that working) Plan 1 was to open the connection, then send the params.
  • wss://stream.binance.com:9443/ws/ {‘method’: ‘SUBSCRIBE’, ‘params’: [‘btcusdt@miniTicker’, ‘ethusdt@miniTicker’], ‘id’:1} as a connection request is rejected (400 Bad Request). Perhaps encoding issues

What does work is to open the connection with (e.g.) wss://stream.binance.com:9443/ws/btcusdt@miniTicker and then send the params:
{‘method’: ‘SUBSCRIBE’, ‘params’: [‘btcusdt@miniTicker’, ‘ethusdt@miniTicker’], ‘id’:1} as a Request.

The request will add to the steamname used in the opening…

you need to connect to server with url:


NO slash in the end.