Websocket issue

Could anyone help me out please.

I've created a web application where trades are made by users on the Binary.com platform. I use the websocket (WebSocket4Net) in a C# environment. I don't want to receive ticks etc. I only need to buy contracts.

Now I've created it like this. When the users logs in by oauth I open the websocket and keep it open. The user can make his trades. But after a couple of hours I get the error:
A call to SSPI failed, see inner exception. System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted --- End of inner exception stack trace --- at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) at SuperSocket.ClientEngine.SslStreamTcpSession.OnAuthenticated(IAsyncResult result)

Am I using the websocket right? Or should I open the socket, make a trade and close the socket? Could anyone please advise.


  • @Alex267 can you please check that websocket connection remains open, because if there is no activity on websocket connection we will close that connection after some time. To keep connection alive you can use https://developers.binary.com/api/#ping

  • Thank you @Raunak for your anwser. I'm using the WebSocket4Net library, because I was told in a other thread on this forum I do not need to ping each time. But indeed the socket is closed before I get this error. I don't mind sending the PING but what would be the advised interval?

  • Hello. Try to send a ping maybe every minute. Also check if you're authorized other wise call authorize again.
    If you want to have your app running long time probably you should make an auto login rutine.


  • What is the best way to check if still authorized?

  • Your application will send error for authenticated calls if you are not authorized, you can check that response and authorize again

Sign In or Register to comment.