Aster.Client.Websocket
1.1.1
dotnet add package Aster.Client.Websocket --version 1.1.1
NuGet\Install-Package Aster.Client.Websocket -Version 1.1.1
<PackageReference Include="Aster.Client.Websocket" Version="1.1.1" />
<PackageVersion Include="Aster.Client.Websocket" Version="1.1.1" />
<PackageReference Include="Aster.Client.Websocket" />
paket add Aster.Client.Websocket --version 1.1.1
#r "nuget: Aster.Client.Websocket, 1.1.1"
#:package Aster.Client.Websocket@1.1.1
#addin nuget:?package=Aster.Client.Websocket&version=1.1.1
#tool nuget:?package=Aster.Client.Websocket&version=1.1.1
Aster websocket API client
This library is a .NET client for the Aster DEX public websocket API found here:
License:
Apache License 2.0
Highlights
- available on NuGet as
Aster.Client.Websocket - covers all documented market-data streams: trades, aggregate trades, kline, mark price, mini tickers, tickers, book tickers, partial and diff order books, liquidation alerts
- authenticated user streams for margin calls, balance/position updates, order trade updates, and config changes
- ready for private streams once the authenticated API is published
- integrates with System.Reactive for composable stream handling
- targets
netstandard2.1,net6,net7,net8
Quick start
var exitEvent = new ManualResetEvent(false);
var url = AsterValues.FuturesApiWebsocketUrl;
using var communicator = new AsterWebsocketCommunicator(url);
using var client = new AsterWebsocketClient(communicator);
client.Streams.TradesStream.Subscribe(resp =>
{
var trade = resp.Data;
Console.WriteLine($"[{trade.Symbol}] {trade.Price} x {trade.Quantity}");
});
client.SetSubscriptions(
new TradeSubscription("btcusdt"),
new OrderBookPartialSubscription("btcusdt", 20)
);
await communicator.Start();
exitEvent.WaitOne(TimeSpan.FromSeconds(30));
User data streams
Authenticate the websocket communicator with your API key and secret to receive private events. The client refreshes the listen key for you every 55 minutes and exposes dedicated observables for each event category.
var communicator = new AsterWebsocketCommunicator(AsterValues.FuturesApiWebsocketUrl);
await communicator.Authenticate(apiKey, new AsterHmac(apiSecret));
var client = new AsterWebsocketClient(communicator);
client.Streams.AccountUpdateStream.Subscribe(update =>
{
foreach (var balance in update.Data.Balances)
{
Console.WriteLine($"Balance for {balance.Asset}: {balance.WalletBalance}");
}
});
client.Streams.OrderUpdateStream.Subscribe(evt =>
{
var order = evt.Order;
Console.WriteLine($"Order {order.Type} {order.Side} -> status {order.Status}, filled {order.QuantityFilled}");
});
client.Streams.ListenKeyExpiredStream.Subscribe(_ =>
Console.WriteLine("Listen key expired – call Authenticate() again to obtain a fresh key."));
await communicator.Start();
More samples:
- console app (link)
Working with streams
- Raw stream:
new Uri("wss://fstream.asterdex.com/ws/btcusdt@aggTrade") - Combined stream: call
client.SetSubscriptions(...)with the desired subscriptions – the client will build/stream?streams=a/b. - Live subscribe/unsubscribe: use
client.Send(new { method = "SUBSCRIBE", params = ..., id = ... }). The JSON contracts mirror the official docs. - Ping/pong handling is automatic; unsolicited
PONGframes are allowed by the server. - One connection may subscribe to at most 200 streams, with an inbound limit of 10 messages/sec.
Backtesting support
AsterFileCommunicator replays delimited files and feeds the client with historical data:
var communicator = new AsterFileCommunicator
{
FileNames = new[] { "data/aster_raw_btcusdt_2018-11-13.txt" },
Delimiter = ";;"
};
var client = new AsterWebsocketClient(communicator);
client.Streams.AggregateTradesStream.Subscribe(resp =>
{
// analyse resp.Data
});
await communicator.Start();
The tests look for uncompressed files in the data/ folder and skip automatically if they are missing.
Reconnection strategy
AsterWebsocketCommunicator retries automatically. Tunable properties:
ReconnectTimeout– inactivity watchdog (default 1 minute)ErrorReconnectTimeout– cooldown after failures (default 1 minute)DisconnectionHappened/ReconnectionHappened– observables that surface connection status
Multi-threading tips
Every stream is an Rx observable. Use ObserveOn to off-load work:
client.Streams.TradesStream
.ObserveOn(TaskPoolScheduler.Default)
.Subscribe(HandleTrade);
To preserve ordering across multiple subscriptions, share a gate:
var gate = new object();
client.Streams.TradesStream
.ObserveOn(TaskPoolScheduler.Default)
.Synchronize(gate)
.Subscribe(HandleTrade);
client.Streams.OrderBookDiffStream
.ObserveOn(TaskPoolScheduler.Default)
.Synchronize(gate)
.Subscribe(HandleBookDiff);
Need help?
Consulting and support are available – contact m@mkotas.cz.
| 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 was computed. 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 was computed. 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
- Newtonsoft.Json (>= 13.0.4)
- System.Reactive (>= 6.0.2)
- Websocket.Client (>= 5.3.0)
-
net6.0
- Newtonsoft.Json (>= 13.0.4)
- System.Reactive (>= 6.0.2)
- Websocket.Client (>= 5.3.0)
-
net7.0
- Newtonsoft.Json (>= 13.0.4)
- System.Reactive (>= 6.0.2)
- Websocket.Client (>= 5.3.0)
-
net8.0
- Newtonsoft.Json (>= 13.0.4)
- System.Reactive (>= 6.0.2)
- Websocket.Client (>= 5.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Aster.Client.Websocket:
| Package | Downloads |
|---|---|
|
Crypto.Websocket.Extensions
Extensions to cryptocurrency websocket clients |
GitHub repositories
This package is not used by any popular GitHub repositories.
Enhancements