SUBSCRIBE - invalid state.


I have set everything up with websockets and all is fine if I connect to;

./exe wss://

My socket connection is esablished and handler called ok.

Received: {“e”:“24hrTicker”,“E”:1702742074270,“s”:“BTCUSDT”,“p”:“652.30”,“P”:“1.558”,“w”:“42149.75”,“c”:“42519.00”,“Q”:“0.006”,“o”:“41866.70”,“h”:“42577.00”,“l”:“41638.10”,“v”:“185779.441”,“q”:“7830556909.16”,“O”:1702655640000,“C”:1702742074269,“F”:4383430762,“L”:4385556923,“n”:2126134}

Thats fine.

However if I connect to;

wss:// (or indeed wss:// )

I connect OK but keep getting an “invalid state” back. The output below illustrates that my SUBSCRIBE message is fine (looks ok to me) and that before doing the send, I am successfully connected to websocket.

Successfully connected to: wss://
sending: {
“method”: “SUBSCRIBE”,
“params”: [
“symbol”: “btcusdt@ticker”
“id”: 23 }
Error sending subscribe: invalid state
Running websocket: wss://
[2023-12-16 15:56:57] [connect] Successful connection
[2023-12-16 15:56:58] [connect] WebSocket Connection v-2 “WebSocket++/0.8.2” /ws 101

Can anybody shed light PLEASE :slight_smile:

“Connected” above means that
_connection = _tls_client.get_connection(_endpoint.c_str(), _ec);

have all completed OK.

I am fairly sure the message I’m sending has to be the source of it but I’m stumped.

Thanks much for any help. Its wrecking my head!! :slightly_smiling_face:


aisling$ websocat -v 'wss://'
[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::ws_client_peer] Connected to ws
{"method":"SUBSCRIBE", "params":["btcusdt@ticker"], "id":1}   

Hello, I’ve used the terminal to connect and subscribe to the WS using websocat and was successful.
Comparing the subscribe message, I think you’re unnecessary sending an extra "symbol" key element.

1 Like

Thanks a million Aisling. Sorted! Have a great day.