Binance.API.Csharp.Client icon indicating copy to clipboard operation
Binance.API.Csharp.Client copied to clipboard

WebSocket doesn't appear to connect

Open SpartanDigitalDotNet opened this issue 7 years ago • 2 comments

Nice work! I've been able to connect end-to-end and am able to use this nicely written library.

However, I seem to be having issues with the ConnectToWebSocket() -- I don't get any messages events in

binanceClient.ListenDepthEndpoint("CNDETH", DepthMessageHandler); and binanceClient.ListenKlineEndpoint("CNDETH", Binance.API.Csharp.Client.Models.Enums.TimeInterval.Minutes_1, KlineHandler);

In ApiClient.cs, ConnectToWebSocket() method seems to call ws.Connect(); ok, but no messages are coming in -- seems to be just dead air. (OnError and OnClose callbacks are never fired)

As a test, I added an OnOpen() and it does get called when ws.Connect(); is executed in ApiClient.cs ws.OnOpen+= (sender, e) => { Console.Write("Opened!"); };

Are the listener methods broken or am I not calling it correctly?
Below is my sample console app Main() code: Keys/Private not shown, just the body:

do
    {
      while (!Console.KeyAvailable)
        {
         if (!started)
           {
               Console.Write("listening...");
                 started = true;
                 //binanceClient.ListenDepthEndpoint("CNDETH", depthMessageHandler);
                 // binanceClient.ListenKlineEndpoint("CNDETH", Binance.API.Csharp.Client.Models.Enums.TimeInterval.Minutes_1, KlineHandler);
                    }
                    // Thread.Sleep(2000);
                }
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);

Handlers

private static void KlineHandler(KlineMessage messageData)
{
       Console.Write("Got KLINE Message!");
        Console.Write($"High: {messageData.KlineInfo.High} Low: {messageData.KlineInfo.Low}");
}

 private static void DepthMessageHandler(DepthMessage messageData)
  {
       Console.Write("Got Message!");
        if (messageData.UpdateId >= DepthMessages.UpdateId)
        {
           DepthMessages = messageData;
         }
        foreach(var m in DepthMessages.Bids)
         {
             Console.Write($"{m.Price}:{m.Quantity}");
         }
 }

Any suggestions?

SpartanDigitalDotNet avatar Jan 25 '18 00:01 SpartanDigitalDotNet

I found the issue! Symbol pairs must be LOWER CASE (ie. ethbtc is valid, not ETHBTC). Hope this helps someone out.

SpartanDigitalDotNet avatar Jan 25 '18 00:01 SpartanDigitalDotNet

Really good catch ReinID!!! thanks for that

plop44 avatar Jan 31 '18 07:01 plop44