Error in Websocket documentation?

Using endpoint wss://ws-api.binance.us:443/ws-api/v3

Ticker websocket API documentation shows an example request where the params field contains an array, but when attempting to subscribe the server returns an error that params should be an object. If I change the array to an object, I need to know what key to use but the documentation does not show this.

Say for example I am subscribing to btcusdt@ticker_1d stream. I am using this format as mentioned in the documentation:

const subscribeMessage = {
  method: "SUBSCRIBE",
  params: ["btcusdt@ticker_1d"],
  id: 1,
};

However the server says it is expected params to be an object, not an array. So I would need something like this:

const subscribeMessage = {
  method: "SUBSCRIBE",
  params: {
        "btcusdt@ticker_1d"
  },
  id: 1,
};

As you can see I am missing the key for the value “btcusdt@ticker_1d”. I do not find in the documentation what the key should be. Should it be streams: “btcusdt@ticker_1d” or something similar?

Hey,
It seems there’s a mix-up between the WebSocket API and the WebSocket Stream. The btcusdt@ticker_1d is a WebSocket Stream.

You should connect to one of the following base URLs: wss://stream.binance.com:9443 or wss://stream.binance.com:443. For more details, refer to the WebSocket Stream documentation

If you’re looking to request Klines using the WebSocket API, you can use the klines method.

Error connecting to wss://stream.binance.com/ bad response.

I used:
const ws = new WebSocket(“wss://stream.binance.com:443”);

Same thing happens with port 9443. I think the issue is I need to be using binance.US as I mentioned in my original post.

If you are based in the US, you will have to use the binance US services.

Invalid ‘params’ in JSON request, expected object. We have come back to the initial issue. As you suggested I switched to the Binance.US server again, which as I stated in my original post, is wss://ws-api.binance.us:443/ws-api/v3.

As explained before, @ticker_ is a wbesocket stream endpoint. You should use a websocket stream base url. For Binance US, it would be wss://stream.binance.us:9443: Binance.US API Documentation

Websocket connection failed. Bad response from server. const ws = new WebSocket(“wss://stream.binance.us:9443”);

Could you give more details on the code you are using to make the request?

What more details do you need? I am creating a websocket and trying to subscribe to a feed. The server returns an error saying my subscription request was invalid because the params field needs to be an object, not an array. The documentation says it needs to be an object, but the example shows an array, not an object. That is why I believe the documentation is incorrect.

What happens when you run the command: websocat -v 'wss://stream.binance.us:9443/ws/btcusdt@ticker_1d'

This works. It is able to reach the server. The issue is the format of my Subscribe message. It is not accepting the “params” field because it is an array, as per your suggestion, where it needs to be an object. I don’t have the key for the stream value.

Results of websocat:

websocat -v ‘wss://stream.binance.us:9443/ws/btcusdt@ticker_1d’

[INFO websocat::lints] Auto-inserting the line mode

[INFO websocat::stdio_threaded_peer] get_stdio_peer (threaded)

[INFO websocat::ws_client_peer] get_ws_client_peer

[INFO websocat::net_peer] Connected to TCP 52.6.52.140:9443

[INFO websocat::ws_client_peer] Connected to ws

{“e”:“1dTicker”,“E”:1733795380756,“s”:“BTCUSDT”,“p”:“-1605.55000000”,“P”:“-1.614”,“w”:“97506.87236218”,“o”:“99455.05000000”,“h”:“100363.54000000”,“l”:“94183.05000000”,“c”:“97849.50000000”,“v”:“55.26685000”,“q”:“5388897.68881000”,“O”:1733708940000,“C”:1733795380171,“F”:29994009,“L”:30002545,“n”:8537}

How about running this command: websocat -v 'wss://stream.binance.us:9443/ws'
Then, when the connection is done: {"method":"SUBSCRIBE", "params":["btcusdt@ticker_1d"], "id":1}

Ok that works. So the URL I should have been using for the websocket is not wss://stream.binance.us:9443 it’s wss://stream.binance.us:9443/ws. I see where I made a mistake. Thanks!