Crypto.Websocket.Extensions
2.17.0
dotnet add package Crypto.Websocket.Extensions --version 2.17.0
NuGet\Install-Package Crypto.Websocket.Extensions -Version 2.17.0
<PackageReference Include="Crypto.Websocket.Extensions" Version="2.17.0" />
<PackageVersion Include="Crypto.Websocket.Extensions" Version="2.17.0" />
<PackageReference Include="Crypto.Websocket.Extensions" />
paket add Crypto.Websocket.Extensions --version 2.17.0
#r "nuget: Crypto.Websocket.Extensions, 2.17.0"
#:package Crypto.Websocket.Extensions@2.17.0
#addin nuget:?package=Crypto.Websocket.Extensions&version=2.17.0
#tool nuget:?package=Crypto.Websocket.Extensions&version=2.17.0
Cryptocurrency websocket extensions
This is a library that provides extensions to cryptocurrency websocket exchange clients.
It helps to unify data models and usage of more clients together.
License:
Apache License 2.0
Features
- installation via NuGet
- full (with all exchange clients) - Crypto.Websocket.Extensions
- core (only interfaces and features) - Crypto.Websocket.Extensions.Core
- targets
netstandard2.1,net6.0,net7.0,net8.0,net9.0,net10.0 - built on Websocket.Client 5.5.0 through the updated exchange clients
- third-party exchange adapters for Bybit, Luno, and VALR remain enabled; NuGet resolves the shared websocket transport to the newer package version
- benchmarked order book hot paths with BenchmarkDotNet
- reactive extensions (Rx.NET)
- integrated logging abstraction (Microsoft.Extensions.Logging)
Performance
The order book implementation is tuned for allocation-sensitive websocket streams. Common L2 diff processing avoids temporary notification objects when nobody is subscribed, keeps internal source-to-orderbook handoff on the single-update path, and uses list-based dispatch for bulk level updates to avoid interface enumerator allocations.
The current benchmark suite focuses on CryptoOrderBook, CryptoOrderBookL2, and related source adapters. In the latest pass, representative BenchmarkDotNet runs showed CryptoOrderBook.BidLevels improving from 17,822 ns / 77 KB to 5,409 ns / 4.8 KB, and CryptoOrderBookL2 diff processing improving from 935 ns / 545 B to 618 ns / 161 B. See the benchmarks README for commands and detailed results.
Supported exchanges
| Logo | Name | Websocket client |
|---|---|---|
![]() |
Bitfinex | bitfinex-client-websocket |
![]() |
BitMEX | bitmex-client-websocket |
![]() |
Binance | binance-client-websocket |
![]() |
Coinbase | coinbase-client-websocket |
![]() |
Bitstamp | bitstamp-client-websocket |
Extensions
Order book
- efficient data structure, based on howtohft blog post
CryptoOrderBookclass - unified order book across all exchanges- support for L2 (grouped by price), L3 (every single order) market data
- support for snapshots and deltas/diffs
- provides streams:
OrderBookUpdatedStream- streams on an every order book updateBidAskUpdatedStream- streams when bid or ask price changed (top level of the order book)TopLevelUpdatedStream- streams when bid or ask price/amount changed (top level of the order book)
- provides properties and methods:
BidLevelsandAskLevels- ordered array of current state of the order bookBidLevelsPerPriceandAskLevelsPerPrice- dictionary of all L3 orders split by priceFindLevelByPriceandFindLevelById- returns specific order book level
Usage:
var url = BitmexValues.ApiWebsocketUrl;
var communicator = new BitmexWebsocketCommunicator(url);
var client = new BitmexWebsocketClient(communicator);
var pair = "XBTUSD";
var source = new BitmexOrderBookSource(client);
var orderBook = new CryptoOrderBook(pair, source);
// orderBook.BidAskUpdatedStream.Subscribe(xxx)
orderBook.OrderBookUpdatedStream.Subscribe(quotes =>
{
var currentBid = orderBook.BidPrice;
var currentAsk = orderBook.AskPrice;
var bids = orderBook.BidLevels;
// xxx
});
await communicator.Start();
Trades
ITradeSource- unified trade info stream across all exchanges
Orders (authenticated)
CryptoOrdersclass - unified orders status across all exchanges with features:- orders view and searching - only executed, search by id, client id, etc.
- our vs all orders - using client id prefix to distinguish between orders
Position (authenticated)
IPositionSource- unified position info stream across all exchanges
Wallet (authenticated)
IWalletSource- unified wallet status stream across all exchanges
More usage examples:
Pull Requests are welcome!
Powerfull Rx.NET
Don't forget that you can do pretty nice things with reactive extensions and observables. For example, if you want to check latest bid/ask prices from all exchanges all together, you can do something like this:
Observable.CombineLatest(new[]
{
bitmexOrderBook.BidAskUpdatedStream,
bitfinexOrderBook.BidAskUpdatedStream,
binanceOrderBook.BidAskUpdatedStream,
})
.Subscribe(HandleQuoteChanged);
// Method HandleQuoteChanged(IList<CryptoQuotes> quotes)
// will be called on every exchange's price change
Multi-threading
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.
client
.Streams
.TradesStream
.Subscribe(trade => { code1 });
client
.Streams
.BookStream
.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.
client
.Streams
.TradesStream
.ObserveOn(TaskPoolScheduler.Default)
.Subscribe(trade => { code1 });
client
.Streams
.BookStream
.ObserveOn(TaskPoolScheduler.Default)
.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();
client
.Streams
.TradesStream
.ObserveOn(TaskPoolScheduler.Default)
.Synchronize(GATE1)
.Subscribe(trade => { code1 });
client
.Streams
.BookStream
.ObserveOn(TaskPoolScheduler.Default)
.Synchronize(GATE1)
.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:
client
.Streams
.TradesStream
.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:
client
.Streams
.TradesStream
.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
.Subscribe();
If you want to process them concurrently (avoid synchronization), then use this
client
.Streams
.TradesStream
.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)
.Subscribe();
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.
Available for help
I do consulting, please don't hesitate to contact me if you have a custom solution you would like me to implement (web, m@mkotas.cz)
Publishing
Packages are published from master using NuGet Trusted Publishing. Update the shared version in Directory.Build.props and add docs/releases/<version>.md before releasing. CI builds all package targets, runs unit and recorded-message integration tests on .NET 8 and .NET 10, and packs both libraries with symbols. It uses NuGet/login to obtain a temporary API key and creates the GitHub release only after verifying that both published packages identify the release commit.
Configure the NuGet policy for user marfusios, owner Marfusios, repository crypto-websocket-extensions, workflow dotnet-core.yml, and both package IDs. Leave the environment field empty. No long-lived NuGet API key is required.
A push to master starts the workflow. To trigger it manually from GitHub CLI:
gh workflow run dotnet-core.yml --ref master
For an interrupted publication, rerun the workflow at the original commit. Already uploaded packages are skipped; CI checks their embedded commit before publishing release notes. Each new release commit needs a new version.
| Product | Versions 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.1
- Aster.Client.Websocket (>= 1.3.0)
- Binance.Client.Websocket (>= 2.8.0)
- Bitfinex.Client.Websocket (>= 4.5.0)
- Bitmex.Client.Websocket (>= 3.5.0)
- Bitstamp.Client.Websocket (>= 1.4.0)
- Bybit.Client.Websocket (>= 1.0.2)
- Coinbase.Client.Websocket (>= 2.5.0)
- Crypto.Websocket.Extensions.Core (>= 2.17.0)
- Hyperliquid.Client.Websocket (>= 1.4.0)
- Luno.Client.Websocket (>= 8.0.2)
- Valr.Client.Websocket (>= 5.3.1)
-
net10.0
- Aster.Client.Websocket (>= 1.3.0)
- Binance.Client.Websocket (>= 2.8.0)
- Bitfinex.Client.Websocket (>= 4.5.0)
- Bitmex.Client.Websocket (>= 3.5.0)
- Bitstamp.Client.Websocket (>= 1.4.0)
- Bybit.Client.Websocket (>= 1.0.2)
- Coinbase.Client.Websocket (>= 2.5.0)
- Crypto.Websocket.Extensions.Core (>= 2.17.0)
- Hyperliquid.Client.Websocket (>= 1.4.0)
- Luno.Client.Websocket (>= 8.0.2)
- Valr.Client.Websocket (>= 5.3.1)
-
net6.0
- Aster.Client.Websocket (>= 1.3.0)
- Binance.Client.Websocket (>= 2.8.0)
- Bitfinex.Client.Websocket (>= 4.5.0)
- Bitmex.Client.Websocket (>= 3.5.0)
- Bitstamp.Client.Websocket (>= 1.4.0)
- Bybit.Client.Websocket (>= 1.0.2)
- Coinbase.Client.Websocket (>= 2.5.0)
- Crypto.Websocket.Extensions.Core (>= 2.17.0)
- Hyperliquid.Client.Websocket (>= 1.4.0)
- Luno.Client.Websocket (>= 8.0.2)
- Valr.Client.Websocket (>= 5.3.1)
-
net7.0
- Aster.Client.Websocket (>= 1.3.0)
- Binance.Client.Websocket (>= 2.8.0)
- Bitfinex.Client.Websocket (>= 4.5.0)
- Bitmex.Client.Websocket (>= 3.5.0)
- Bitstamp.Client.Websocket (>= 1.4.0)
- Bybit.Client.Websocket (>= 1.0.2)
- Coinbase.Client.Websocket (>= 2.5.0)
- Crypto.Websocket.Extensions.Core (>= 2.17.0)
- Hyperliquid.Client.Websocket (>= 1.4.0)
- Luno.Client.Websocket (>= 8.0.2)
- Valr.Client.Websocket (>= 5.3.1)
-
net8.0
- Aster.Client.Websocket (>= 1.3.0)
- Binance.Client.Websocket (>= 2.8.0)
- Bitfinex.Client.Websocket (>= 4.5.0)
- Bitmex.Client.Websocket (>= 3.5.0)
- Bitstamp.Client.Websocket (>= 1.4.0)
- Bybit.Client.Websocket (>= 1.0.2)
- Coinbase.Client.Websocket (>= 2.5.0)
- Crypto.Websocket.Extensions.Core (>= 2.17.0)
- Hyperliquid.Client.Websocket (>= 1.4.0)
- Luno.Client.Websocket (>= 8.0.2)
- Valr.Client.Websocket (>= 5.3.1)
-
net9.0
- Aster.Client.Websocket (>= 1.3.0)
- Binance.Client.Websocket (>= 2.8.0)
- Bitfinex.Client.Websocket (>= 4.5.0)
- Bitmex.Client.Websocket (>= 3.5.0)
- Bitstamp.Client.Websocket (>= 1.4.0)
- Bybit.Client.Websocket (>= 1.0.2)
- Coinbase.Client.Websocket (>= 2.5.0)
- Crypto.Websocket.Extensions.Core (>= 2.17.0)
- Hyperliquid.Client.Websocket (>= 1.4.0)
- Luno.Client.Websocket (>= 8.0.2)
- Valr.Client.Websocket (>= 5.3.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.17.0 | 42 | 9/25/2026 |
| 2.16.0 | 848 | 5/13/2026 |
| 2.15.2 | 1,637 | 10/20/2025 |
| 2.15.1 | 237 | 10/17/2025 |
| 2.15.0 | 252 | 10/16/2025 |
| 2.14.0 | 268 | 10/15/2025 |
| 2.13.8 | 419 | 10/2/2025 |
| 2.13.6 | 258 | 10/1/2025 |
| 2.13.5 | 248 | 10/1/2025 |
| 2.13.4 | 248 | 10/1/2025 |
| 2.13.3 | 248 | 10/1/2025 |
| 2.13.2 | 242 | 10/1/2025 |
| 2.13.1 | 240 | 10/1/2025 |
| 2.13.0 | 258 | 10/1/2025 |
| 2.12.0 | 279 | 9/30/2025 |
| 2.11.0 | 249 | 9/29/2025 |
| 2.10.0 | 340 | 5/22/2025 |
| 2.9.0 | 340 | 6/17/2024 |
| 2.8.0 | 256 | 4/29/2024 |
| 2.7.1 | 568 | 2/20/2024 |
Refresh exchange clients and runtime dependencies; include order book allocation improvements. See https://github.com/Marfusios/crypto-websocket-extensions/releases/tag/v2.17.0.




