Cant get a secure websocket connection to gdax working

433 views Asked by At

I'm trying to connect to GDAX websocket feed from C# (Target Framework: Core 2.0)

I'm using this NodeJS implementation as a reference.

My code:

var ws = new WebSocket("wss://ws-feed.gdax.com");
ws.Security.AllowUnstrustedCertificate = true; // doesn't matter if I remove this line
ws.Send(json);
ws.MessageReceived += (sender, args) => _log.LogInformation(args.Message);

Where json (Reference):

{
  "type": "subscribe",
  "product_ids": [
    "BTC-EUR"
  ],
  "channels": [
    "ticker"
  ]
}

I don't see any errors in the log and I tried different libraries for WebSocket. I'm fine with solutions that use other libraries.

1

There are 1 answers

0
SpaceMonkey On BEST ANSWER
        var ws = new WebSocket4Net.WebSocket(url);
        ws.Open();


        ws.DataReceived += (sender, args) => Console.WriteLine(args.Data);
        ws.MessageReceived += (sender, args) => Console.WriteLine(args.Message);
        ws.Opened += (sender, args) =>
        {
            Console.WriteLine("opened: " + args);
            ws.Send(json);
        };
        ws.Error += (sender, args) => Console.WriteLine("error: " + args);
        Console.ReadLine();

The problem was that I was sending straight away after calling Open. I should wait and send on the Opened event.