Kraken WebSocket API .NET Client Library
master | develop | nuget |
---|---|---|
C# / .NET Standard Client for connecting to the public kraken.com WebSocket API
API Documentation
See the official documentation fur further information https://www.kraken.com/features/websocket-api
Getting started
Installing it in your project environment
Get the current version from NuGet Gallery using the Package Manager / .NET CLI
PM> Install-Package Kraken.WebSockets # Package Manager
> dotnet add package Kraken.WebSockets # .NET CLI
For detailed information on the installing of pre-release versions please refer to the NuGet Gallery itself.
Create a connection and listen for events
Creating a connection is pretty easy but will also be improved in the future. But for now just do it like this:
using (var client = KrakenApi.ClientFactory.Create("wss://ws-beta.kraken.com"))
{
client.SystemStatusChanged += (sender, e) => Console.WriteLine($"System status changed");
client.SubscriptionStatusChanged += (sender, e) => Console.WriteLine($"Subscription status changed"); ;
client.TickerReceived += (sender, e) => Console.WriteLine($"Ticker received");
client.OhlcReceived += (sender, e) => Console.WriteLine($"Ohlc received");
client.TradeReceived += (sender, e) => Console.WriteLine($"Trade received");
client.SpreadReceived += (sender, e) => Console.WriteLine($"Spread received");
client.BookSnapshotReceived += (sender, e) => Console.WriteLine($"BookSnapshot received");
client.BookUpdateReceived += (sender, e) => Console.WriteLine($"BookUpdate received");
await kraken.ConnectAsync();
// Do something with it and keep the connection open
}
// closing the using-block the connection will be closed and disposed.
You can also find a running example in the repository.
Attach your logging framework
With the Microsoft.Extensions.Logging.Abstractions
in place you are not limited to a specific logging framework. Each logging framework which supports this abstraction layer can be attached to this library. Just to name a few of them:
- log4net
- Serilog
- NLog
- … and many more
To enable the logging just call the provided extension method on your ILoggerFactory
of your application.
// Using the logging from ASP.NET Core MVC
// Startup.cs
using Kraken.WebSockets.Logging;
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// ... source omitted
loggerFactory.AddKrakenWebSockets(); // Enables the configured logging factory for the logs in Kraken.WebSockets
// ... source omitted
}
Support
If you like the stuff I do, please don’t hesitate to support my actions by donating me a coffee!