Binance Public API Connector DotNET Keep WebSocket Alive

Hi

I downloaded the “Binance Public API Connector DotNET” NuGet package into a simple c# console application.

Following the instructions from the readme file GitHub - binance/binance-connector-dotnet: Lightweight connector for integration with Binance API

using System;
using System.Threading;
using System.Threading.Tasks;
using Binance.Spot;

class Program
{
    static async Task Main(string[] args)
    {
        var websocket = new MarketDataWebSocket("btcusdt@aggTrade");

        websocket.OnMessageReceived(
            (data) =>
        {
            Console.WriteLine(data);

            return Task.CompletedTask;
        }, CancellationToken.None);

        await websocket.ConnectAsync(CancellationToken.None);
    }
}

I Changed the variable from btcusdt@aggTrade to !bookTicker" hoping I would get a continuous feed of prices from the Live Binance websocket.

But all I get is a few lines back and the feed finishes

So I pulled the example code from git hub GitHub - binance/binance-connector-dotnet: Lightweight connector for integration with Binance API to see if that would give me clues on how to get a continuous feed of prices from all symbols. But I found the Tests also only last a few seconds. There only seems to be tests cases that connect to the sample code Libraries so I could not use these samples to see where I was going wrong.

Is anyone able to help me understand why my feed only lasts a few seconds using the official Binance sample code?

Thanks

Thanks for feedback.

The !bookTicker will be removed from November, it is recommended to use <symbol>@bookTicker instead. Please try if you can get data from this steam.

Hi Dino

Thanks for pointing me to the Change Log, I will have to rework my solution.

Even after changing from !bookTicker to btcusdt@bookTicker/bnbbtc@bookTicker etc I was still experiencing the problem.

I deployed the app, and it was closing the console as soon as I ran it, So I added Console.ReadLine(); to the my code to stop it closing, to see what was going on. As Soon as I did this it started to work. Not sure why…

Solution: Add Console.ReadLine(); to Binance sample code. GitHub - binance/binance-connector-dotnet: Lightweight connector for integration with Binance API

Thanks

Connectors:

The following are lightweight libraries that work as connectors to the Binance public API, written in different languages:

How to get it for C / C ++ ?