websockets in delphi

Hi everyone.
IActually i can send orders, consult account info, etc.
But i have problem to connect via websockets and receive data information.
To connect i use this code, where cs is a clientsocket component

 cs.Host := 'stream.binance.com';
 cs.port := 9443;
 cs.Open;

with the above code i can connect and there is no error

to subscribe i tryed this code
s := ‘/ws/{“method”: SUBSCRIBE",“params”:“btcusdt@trade”,“btcusdt@aggTrade”,“btcusdt@depth”],“id”: 1}’;

or

s := ‘/ws/btcusdt@trade’;
cs.Socket.SendText(s);

but there is no event on cs.socket.readtext…

Someone have some idea what i´m doing wrong?

How could i connect and receive price data without consulting it in an active way via API ‘price’?
Thanks in advance

Hi.
Though I’m not so sure about how you handle the s and cs, lemme try to help.
To subscribe the websocket stream, the first approach should change /ws to /stream and send the object {"method":.., "params":..} after the connection is established.

The second approach should work if the complete path wss://stream.binance.com:9443/ws/btcusdt@trade is specified when initiating the connection. Please check the program again, thanks.

You can find the solution here:

I wrote a Delphi program which

  • can connect to Binance with REST comps
  • use websocket to SUBSCRIBE to crypto history

I hope I could help.