无法获得与gdax工作的安全websocket连接

时间:2017-12-10 18:40:49

标签: c# asp.net-core .net-core gdax-api

我尝试从C#(目标框架:Core 2.0)连接到GDAX websocket源

I'm using this NodeJS implementation as a reference.

我的代码:

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);

json(Reference):

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

我没有在日志中看到任何错误,我为WebSocket尝试了不同的库。我对使用其他库的解决方案很满意。

1 个答案:

答案 0 :(得分:1)

        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();

问题是我在打电话给Open之后立即发送了。我应该等待并发送Opened事件。