Giter Club home page Giter Club logo

kraken-wsapi-dotnet's Introduction

master develop nuget
Build Status Build Status Stable

kraken-wsapi-dotnet

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:

var krakenApi = new KrakenApi()
    .ConfigureWebsocket("wss://ws.kraken.com");

using (var client = krakenApi.BuildClient())
{
    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.

Subscribe to private events

Starting with their version 0.3.0 of the Websocket API kraken.com provides access to sensitive private account information like trades and orders. In order to gain access you need to authenticate.

We support an easy and feasible way to retrieve a token and pass it to the subscription:

// Configure the API provider
var krakenApi = new KrakenApi()
    .ConfigureWebsocket("wss://ws.kraken.com")
    .ConfigureAuthentication(
        configuration.GetValue<string>("API_URL"),
        configuration.GetValue<string>("API_KEY"),
        configuration.GetValue<string>("API_SECRET"));

// retrieve the token
var token = await krakenApi.AuthenticationClient.GetWebsocketToken();

// Pass the token to a private subscription
await client.SubscribeAsync(new Subscribe(null, new SubscribeOptions(SubscribeOptionNames.OwnTrades, token.Token)));

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!

Buy me a coffeeBuy me a coffee

-Me

Analytics

Get more details at codescene.io.

kraken-wsapi-dotnet's People

Contributors

dependabot[bot] avatar m4cx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kraken-wsapi-dotnet's Issues

Support openOrders message

openOrders

Publication: Open orders, feed to show all the open orders belonging to the user authenticated API key. Initial snapshot will provide list of all open orders and then any updates will to the open orders list will be sent.

Improve subscription handling

When receiving information from the websocket regarding subscriptionStatus the information is currently interpreted by the same classes as a requesting a subscription. This should be separated.

Also the error handling can be improved.

Book Checksum

https://docs.kraken.com/websockets-beta/#book-checksum

Extend BookUpdateMessage for new Checksum field in bids and asks.

Implement calculation of Checksum for the current book implemented. Allthough this library does not store any information, it might be of help for users to just call an appropriate function for calculation.

Support Authentication for private messages

Authentication (for Private Messages, preview only)

The API client must request an authentication "token" via the following REST API endpoint "getWebSocketsToken" to connect to WebSockets Private endpoints. The token expires every 60 minutes. Please reach out to your Account Manager to receive the token endpoint url to connect to test environment.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.