Jay
Jay

Reputation: 11

C# Webscoket Subscribing Errors on Deribit Exchange

Im trying to get the public market data via Websocket on Deribit Exchange.

When i tried with Python at below, it works.

msg = \
    {"jsonrpc": "2.0",
     "method": "public/subscribe",
     "id": 42,
     "params": {
        "channels": ["book.BTC-PERPETUAL.100ms"]}
    }

msg = json.dumps(msg)



async with websockets.connect('wss://test.deribit.com/ws/api/v2') as websocket:
    await websocket.send(msg)
    while websocket.open:
        response = await websocket.recv()

        print(response)

But When i tried it with C#, it occurs an error. What is problem with C# Codes?

Here is the result of codes at below.

Fatal|WebSocket.Connect|WebSocketSharp.WebSocketException: An error has occurred during a TLS handshake. ---> System.Security.Authentication.AuthenticationException:

public void DeribitWs()
        {
            JObject obj1 = new JObject();
            JObject paramObj = new JObject();
            JArray paramO = new JArray();
            paramO.Add("book.BTC-PERPETUAL.100ms");

            obj1["jsonrpc"] = "2.0";
            obj1["method"] = "public/subscribe";
            obj1["id"] = 42;
            paramObj["channels"] = paramO;
            obj1["params"] = paramObj;

            string aaa = string.Format("{0}", obj1.ToString());

            string sendMessage = JsonConvert.SerializeObject(obj1, Formatting.None);

            Console.WriteLine(sendMessage);

            WebSocket deribitWebsocket = new WebSocket("wss://test.deribit.com/ws/api/v2");
            deribitWebsocket.OnMessage += DeribitTickMessage;

            deribitWebsocket.Connect();

            if (deribitWebsocket.ReadyState == WebSocketState.Open)
            {
                deribitWebsocket.Send(sendMessage);
            }
        }

Upvotes: 1

Views: 242

Answers (1)

Artur
Artur

Reputation: 546

Check the TLS versions used by client and server. If they are not equal that might be a problem.

https://github.com/sta/websocket-sharp/issues/438

Upvotes: 1

Related Questions