Kraken.Net
Kraken.Net is a strongly typed client library for accessing the Kraken REST and Websocket API. All data is mapped to readable models and enum values. Additional features include an implementation for maintaining a client side order book, easy integration with other exchange client libraries and more.
Supported Frameworks
The library is targeting both .NET Standard 2.0
and .NET Standard 2.1
for optimal compatibility
.NET implementation | Version Support |
---|---|
.NET Core | 2.0 and higher |
.NET Framework | 4.6.1 and higher |
Mono | 5.4 and higher |
Xamarin.iOS | 10.14 and higher |
Xamarin.Android | 8.0 and higher |
UWP | 10.0.16299 and higher |
Unity | 2018.1 and higher |
Discord
A Discord server is available here. Feel free to join for discussion and/or questions around the CryptoExchange.Net and implementation libraries.
Support the project
DonateMake a one time donation in a crypto currency of your choice. If you prefer to donate a currency not listed here please contact me.
Btc: bc1q277a5n54s2l2mzlu778ef7lpkwhjhyvghuv8qf
Eth: 0xcb1b63aCF9fef2755eBf4a0506250074496Ad5b7
USDT (TRX): TKigKeJPXZYyMVDgMyXxMf17MWYia92Rjd
Alternatively, sponsor me on Github using Github Sponsors.
Getting Started
The packge is available on Nuget. After installing the package the Kraken API is available by using the KrakenRestClient
and KrakenSocketClient
.
Installation
Add the package via dotnet, or add it via the package manager.
dotnet add package KrakenExchange.Net
API Access
Kraken.Net can be configured using Dotnet dependency injection, after which the clients can be injected into your services. It also correctly configures logging and HttpClient usage.
builder.Services.AddKraken(options => {
// Options can be configured here, for example:
options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
The IKrakenRestClient
and IKrakenSocketClient
can then be injected.
Alternatively the rest and socket client can be constructed directly
var restClient = new KrakenRestClient(options => {
// Options can be configured here, for example:
options.ApiCredentials = new ApiCredentials("APIKEY", "APISECRET");
});
var socketClient = new KrakenSocketClient();
Rate limiting
By default a rate limiter is enabled which makes sure the server rate limits aren't exceeded. For more info on what the rate limits for the Kraken API are see the Spot API docs and Futures API docs. Note that rate limiting is only implemented to prevent going over the request rate limit, it does not apply for order limits.
Whether client ratelimiting is enabled in the library and what the behaviour should be when the limit is reached can be controlled with the RatelimiterEnabled
and RateLimitingBehaviour
client options
services.AddKraken(x =>
x.RatelimiterEnabled = true;
x.RateLimitingBehaviour = RateLimitingBehaviour.Wait;
}, x =>
{
x.RatelimiterEnabled = true;
x.RateLimitingBehaviour = RateLimitingBehaviour.Wait;
});
To be notified of when a rate limit is hit the static KrakenExchange.RateLimiter
exposes an event which triggers when a rate limit is reached
KrakenExchange.RateLimiter.RateLimitTriggered += (rateLimitEvent) => Console.WriteLine("Limit triggered: " + rateLimitEvent);
// Output: Limit triggered: RateLimitEvent { ApiLimit = Spot Rest, LimitDescription = Limit of 15 with a decay rate of 0,33, RequestDefinition = POST 0/private/TradesHistory authenticated, Host = api.kraken.com, Current = 14, RequestWeight = 2, Limit = 15, TimePeriod = 00:00:01, DelayTime = 00:00:04, Behaviour = Wait }
Kraken applies different rate limits based on the account verification tier. By default the rate limit is set to the most conservative Starter
tier. To change the rate limit tier call the Configure
method
KrakenExchange.RateLimiter.Configure(Kraken.Net.Enums.RateLimitTier.Pro);
Examples
Spot API
Get SymbolsGet a list of supported spot symbols
var krakenClient = new KrakenRestClient();
var result = await krakenClient.SpotApi.ExchangeData.GetSymbolsAsync();
Get Symbol TickerGet the 24h price ticker of a spot symbol
var krakenClient = new KrakenRestClient();
var result = await krakenClient.SpotApi.ExchangeData.GetTickerAsync("ETHUSDT");
Get Recent TradesGet the most recent trades for a spot symbol
var krakenClient = new KrakenRestClient();
var result = await krakenClient.SpotApi.ExchangeData.GetTradeHistoryAsync("ETHUSDT");
Get BalancesGet asset balances of the spot account
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.SpotApi.Account.GetBalancesAsync();
Place Limit OrderPlace a new limit order for buying 0.1 ETH at a price of 2000 USDT
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.SpotApi.Trading.PlaceOrderAsync(
"ETHUSDT",
Kraken.Net.Enums.OrderSide.Buy,
Kraken.Net.Enums.OrderType.Limit,
0.1m,
2000);
Place Market OrderPlace a new market order for buying 50 USDT worth of ETH at the best available price
var result = await krakenClient.SpotApi.Trading.PlaceOrderAsync(
"ETHUSDT",
Kraken.Net.Enums.OrderSide.Buy,
Kraken.Net.Enums.OrderType.Market,
50,
orderFlags: new[] { Kraken.Net.Enums.OrderFlags.OrderVolumeExpressedInQuoteAsset }
);
Get Order InfoRetrieve order information for a specific order
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.SpotApi.Trading.GetOrderAsync("123");
Cancel an orderCancel a currently active order
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.SpotApi.Trading.CancelOrderAsync("123");
Futures API
Get SymbolsGet a list of supported usd futures symbols
var krakenClient = new KrakenRestClient();
var result = await krakenClient.FuturesApi.ExchangeData.GetSymbolsAsync();
Get Symbol TickersGet the 24h price ticker of futures symbols
var krakenClient = new KrakenRestClient();
var result = await krakenClient.FuturesApi.ExchangeData.GetTickersAsync();
Get Recent TradesGet the most recent trades for a futures symbol
var krakenClient = new KrakenRestClient();
var result = await krakenClient.FuturesApi.ExchangeData.GetTradesAsync("ETHUSDT");
Get BalancesGet balance of the perpetual futures account
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.FuturesApi.Account.GetBalancesAsync();
Get PositionsGet open positions
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.FuturesApi.Trading.GetOpenPositionsAsync();
Place Limit OrderPlace a new limit order for 0.1 ETH at a price of 2000 USDT
var krakenClient = new KrakenRestClient(options => {
options.ApiCredentials = new ApiCredentials("KEY", "SECRET");
});
var result = await krakenClient.FuturesApi.Trading.PlaceOrderAsync(
"ETHUSDT",
Kraken.Net.Enums.OrderSide.Buy,
Kraken.Net.Enums.FuturesOrderType.Limit,
0.1m,
2000);