Binance.Client.Websocket 2.3.1

dotnet add package Binance.Client.Websocket --version 2.3.1                
NuGet\Install-Package Binance.Client.Websocket -Version 2.3.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Binance.Client.Websocket" Version="2.3.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Binance.Client.Websocket --version 2.3.1                
#r "nuget: Binance.Client.Websocket, 2.3.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Binance.Client.Websocket as a Cake Addin
#addin nuget:?package=Binance.Client.Websocket&version=2.3.1

// Install Binance.Client.Websocket as a Cake Tool
#tool nuget:?package=Binance.Client.Websocket&version=2.3.1                


Binance websocket API client Build Status NuGet version

This is a C# implementation of the Binance websocket API found here:

Releases and breaking changes


Apache License 2.0


  • installation via NuGet (Binance.Client.Websocket)
  • public and authenticated API
  • targeting .NET Standard 2.0 (.NET Core, Linux/MacOS compatible)
  • reactive extensions (Rx.NET)
  • integrated logging abstraction (LibLog)


var exitEvent = new ManualResetEvent(false);
var url = BinanceValues.ApiWebsocketUrl;

using (var communicator = new BinanceWebsocketCommunicator(url))
    using (var client = new BinanceWebsocketClient(communicator))
        client.Streams.TradesStream.Subscribe(response =>
            var trade = response.Data;
            Console.WriteLine($"Trade executed [{trade.Symbol}] price: {trade.Price}");

            new TradeSubscription("btcusdt"),
            new TradeSubscription("ethbtc"),
            new TradeSubscription("bnbbtc"),
        await communicator.Start();


More usage examples:

  • console sample (link)
  • integration tests (link)
  • desktop sample (link)

API coverage

PUBLIC Covered
Aggregate trades
Individual mini tickers
All mini tickers
Individual tickers
All tickers
Partial orderbook
Diff. orderbook
Account update
Balance update
Order update

Pull Requests are welcome!

Other websocket libraries

<table> <tr>

<td> <a href=""><img src="" height="80px"></a> <br /> <a href="">Extensions</a> <br /> <span>All order books together, etc.</span> </td>

<td> <a href=""><img src=""></a> <br /> <a href="">Bitmex</a> </td>

<td> <a href=""><img src=""></a> <br /> <a href="">Bitfinex</a> </td>

<td> <a href=""><img src=""></a> <br /> <a href="">Coinbase</a> </td>

</tr> </table>


There is a built-in reconnection which invokes after 1 minute (default) of not receiving any messages from the server. It is possible to configure that timeout via communicator.ReconnectTimeoutMs. Also, there is a stream ReconnectionHappened which sends information about a type of reconnection. However, if you are subscribed to low rate channels, it is very likely that you will encounter that timeout - higher the timeout to a few minutes or call PingRequest by your own every few seconds.

In the case of Binance outage, there is a built-in functionality which slows down reconnection requests (could be configured via communicator.ErrorReconnectTimeoutMs, the default is 1 minute).


The library is prepared for backtesting. The dependency between Client and Communicator is via abstraction IBinanceCommunicator. There are two communicator implementations:

  • BinanceWebsocketCommunicator - a realtime communication with Binance via websocket API.
  • BinanceFileCommunicator - a simulated communication, raw data are loaded from files and streamed. If you are interested in buying historical raw data (trades, order book events), contact me.

Feel free to implement IBinanceCommunicator on your own, for example, load raw data from database, cache, etc.


var communicator = new BinanceFileCommunicator();
communicator.FileNames = new[]
communicator.Delimiter = ";;";

var client = new BinanceWebsocketClient(communicator);
client.Streams.TradesStream.Subscribe(response =>
    // do something with trade

await communicator.Start();


Observables from Reactive Extensions are single threaded by default. It means that your code inside subscriptions is called synchronously and as soon as the message comes from websocket API. It brings a great advantage of not to worry about synchronization, but if your code takes a longer time to execute it will block the receiving method, buffer the messages and may end up losing messages. For that reason consider to handle messages on the other thread and unblock receiving thread as soon as possible. I've prepared a few examples for you:

Default behavior

Every subscription code is called on a main websocket thread. Every subscription is synchronized together. No parallel execution. It will block the receiving thread.

    .Subscribe(trade => { code1 });

    .Subscribe(book => { code2 });

// 'code1' and 'code2' are called in a correct order, according to websocket flow
// ----- code1 ----- code1 ----- ----- code1
// ----- ----- code2 ----- code2 code2 -----
Parallel subscriptions

Every single subscription code is called on a separate thread. Every single subscription is synchronized, but different subscriptions are called in parallel.

    .Subscribe(trade => { code1 });

    .Subscribe(book => { code2 });

// 'code1' and 'code2' are called in parallel, do not follow websocket flow
// ----- code1 ----- code1 ----- code1 -----
// ----- code2 code2 ----- code2 code2 code2
Parallel subscriptions with synchronization

In case you want to run your subscription code on the separate thread but still want to follow websocket flow through every subscription, use synchronization with gates:

private static readonly object GATE1 = new object();
    .Subscribe(trade => { code1 });

    .Subscribe(book => { code2 });

// 'code1' and 'code2' are called concurrently and follow websocket flow
// ----- code1 ----- code1 ----- ----- code1
// ----- ----- code2 ----- code2 code2 ----

Async/Await integration

Using async/await in your subscribe methods is a bit tricky. Subscribe from Rx.NET doesn't await tasks, so it won't block stream execution and cause sometimes undesired concurrency. For example:

    .Subscribe(async trade => {
        // do smth 1
        await Task.Delay(5000); // waits 5 sec, could be HTTP call or something else
        // do smth 2

That await Task.Delay won't block stream and subscribe method will be called multiple times concurrently. If you want to buffer messages and process them one-by-one, then use this:

    .Select(trade => Observable.FromAsync(async () => {
        // do smth 1
        await Task.Delay(5000); // waits 5 sec, could be HTTP call or something else
        // do smth 2
    .Concat() // executes sequentially

If you want to process them concurrently (avoid synchronization), then use this

    .Select(trade => Observable.FromAsync(async () => {
        // do smth 1
        await Task.Delay(5000); // waits 5 sec, could be HTTP call or something else
        // do smth 2
    .Merge() // executes concurrently
    // .Merge(4) you can limit concurrency with a parameter
    // .Merge(1) is same as .Concat()
    // .Merge(0) is invalid (throws exception)

More info on Github issue.

Don't worry about websocket connection, those sequential execution via .Concat() or .Merge(1) has no effect on receiving messages. It won't affect receiving thread, only buffers messages inside TradesStream.

But beware of producer-consumer problem when the consumer will be too slow. Here is a StackOverflow issue with an example how to ignore/discard buffered messages and always process only the last one.

Desktop application (WinForms or WPF)

Due to the large amount of questions about integration of this library into a desktop application (old full .NET Framework), I've prepared WinForms example (link).

WinForms example screen

Available for help

I do consulting, please don't hesitate to contact me if you need a paid help
(web, nostr,

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Binance.Client.Websocket:

Package Downloads

Extensions to cryptocurrency websocket clients

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.1 597 2/20/2024
2.3.0 114 2/19/2024
2.2.1 252 2/16/2024
2.2.0 115 2/15/2024
2.1.10 3,764 11/20/2021
2.0.24 1,241 12/6/2020
2.0.22 4,911 8/19/2020
2.0.20 4,310 7/2/2020
2.0.19 1,426 5/4/2020
2.0.18 844 5/4/2020
2.0.17 814 5/4/2020
2.0.14 4,206 12/18/2019
2.0.13 1,451 12/10/2019
2.0.12 1,841 12/6/2019
2.0.11 858 12/6/2019
2.0.9 1,380 11/20/2021
1.0.10 2,766 10/8/2019
1.0.9 4,309 8/4/2019
1.0.8 4,567 4/23/2019
1.0.7 1,968 4/7/2019
1.0.6 4,770 3/27/2019
1.0.5 915 3/26/2019
1.0.4 947 3/26/2019
1.0.3 954 3/26/2019