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:
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.
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
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.
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.
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!