Binance.API.Csharp.Client
Binance.API.Csharp.Client copied to clipboard
WebSocket doesn't appear to connect
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?
I found the issue! Symbol pairs must be LOWER CASE (ie. ethbtc
is valid, not ETHBTC). Hope this helps someone out.
Really good catch ReinID!!! thanks for that