Kraken WebSocket API

Overview

Kraken WebSockets Public API offers real-time market data updates. WebSockets is a bidirectional protocol offering fastest real-time data, helping you build real-time applications. The message types presented below do not require authentication.

 

General Considerations

All messages sent and received via WebSockets are encoded in JSON format 

All floating point fields (including timestamps) are quoted to preserve precision. 

Format of each tradeable pair is A/B, where A and B are ISO 4217-A3 for standardized assets and popular unique symbol if not standardized. 

Timestamps should not be considered unique and not be considered as aliases for transaction ids. Also, the granularity of timestamps is not representative of transaction rates. 

 

Supported Pairs

ADA/CAD, ADA/ETH, ADA/EUR, ADA/USD, ADA/XBT, ATOM/CAD, ATOM/ETH, ATOM/EUR, ATOM/USD, ATOM/XBT, BCH/EUR, BCH/USD, BCH/XBT, DASH/EUR, DASH/USD, DASH/XBT, EOS/ETH, EOS/EUR, EOS/USD, EOS/XBT, GNO/ETH, GNO/EUR, GNO/USD, GNO/XBT, QTUM/CAD, QTUM/ETH, QTUM/EUR, QTUM/USD, QTUM/XBT, USDT/USD, ETC/ETH, ETC/XBT, ETC/EUR, ETC/USD, ETH/XBT, ETH/CAD, ETH/EUR, ETH/GBP, ETH/JPY, ETH/USD, LTC/XBT, LTC/EUR, LTC/USD, MLN/ETH, MLN/XBT, REP/ETH, REP/XBT, REP/EUR, REP/USD, STR/EUR, STR/USD, XBT/CAD, XBT/EUR, XBT/GBP, XBT/JPY, XBT/USD, BTC/CAD, BTC/EUR, BTC/GBP, BTC/JPY, BTC/USD, XDG/XBT, XLM/XBT, DOGE/XBT, STR/XBT, XLM/EUR, XLM/USD, XMR/XBT, XMR/EUR, XMR/USD, XRP/XBT, XRP/CAD, XRP/EUR, XRP/JPY, XRP/USD, ZEC/XBT, ZEC/EUR, ZEC/JPY, ZEC/USD, XTZ/CAD, XTZ/ETH, XTZ/EUR, XTZ/USD, XTZ/XBT

 

Methods

Ping

Client can ping server to determine whether connection is alive, server responds with pong. This is an application level ping as opposed to default ping in WebSockets standard which is server initiated

 

Ticker

Ticker information includes best ask and best bid prices, 24hr volume, last trade price, volume weighted average price, etc for a given currency pair. A ticker message is published every time a trade or a group of trade happens.

Subscribe to a ticker calling SubscribeTicker method:

SubscribeTicker(['XBT/USD']);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeTicker method:

UnSubscribeTicker(['XBT/USD']);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnKrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Ticker updates will be notified in OnKrakenData event.

 

 

OHLC

When subscribed for OHLC, a snapshot of the last valid candle (irrespective of the endtime) will be sent, followed by updates to the running candle. For example, if a subscription is made to 1 min candle and there have been no trades for 5 mins, a snapshot of the last 1 min candle from 5 mins ago will be published. The endtime can be used to determine that it is an old candle.

Subscribe to a OHLC calling SubscribeOHLC method, you must pass pair and interval.

SubscribeOHLC(['XBT/USD'], kin1min);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeOHLC method:

UnSubscribeOHLC(['XBT/USD'], kin1min);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnKrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

OHLC updates will be notified in OnKrakenData event.

  

Trade

Trade feed for a currency pair.

Subscribe to Trade feed calling SubscribeTrade method.

SubscribeTrade(['XBT/USD']);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeTrade method:

UnSubscribeTrade(['XBT/USD']);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Trade updates will be notified in OnKrakenData event.

 

 

Book

Order book levels. On subscription, a snapshot will be published at the specified depth, following the snapshot, level updates will be published.

Subscribe to a Book calling SubscribeBook method, you must pass pair and depth.

SubscribeBook(['XBT/USD'], kde10);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeBook method:

UnSubscribeBook(['XBT/USD'], kde10);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnKrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Book updates will be notified in OnKrakenData event.

 

 

Spread

Spread feed to show best bid and ask price for subscribed asset pair. Bid volume and ask volume is part of the message too.

Subscribe to Spread feed calling SubscribeSpread method.

SubscribeSpread(['XBT/USD']);

If subscription is successful, OnKrakenSubscribed event will be called:

procedure OnKrakenSubscribed(Sender: TObject;ChannelId: Integer; Pair, Subscription, ChannelName: string; ReqID:Integer);

begin

  DoLog('#subscribed: ' + Subscription + ' ' + Pair + ' ' + ChannelName);

end;

UnSubscribe calling UnSubscribeSpread method:

UnSubscribeSpread(['XBT/USD']);

If unsubscription is successful, OnKrakenUnSubscribed event will be called:

procedure OnrakenUnSubscribed(Sender: TObject; ChannelId: Integer; Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#unsubscribed: ' + Subscription + ' ' + Pair);

end;

If there is an error while trying to subscribe / unsubscribe, OnKrakenSubscriptionError event will be called.

procedure OnKrakenSubscriptionError(Sender: TObject; ErrorMessage, Pair, Subscription: string; ReqID: Integer);

begin

  DoLog('#subscription error: ' + ErrorMessage);

end;

Spread updates will be notified in OnKrakenData event.

 

 

Other Methods

You can subscribe / unsubscribe to all channels with one method:

SubscribeAll(['XBT/USD']);

UnSubscribeAll(['XBT/USD']);

OHLC interval value is 1 if all channels subscribed.

 

Events

OnConnect: when websocket client is connected to client.

OnKrakenConnect: called after successful websocket connection and when server send system status.

OnKrakenSystemStatus: called when system status changes.

OnKrakenSubscribed: called after a successful subscription to a channel.

OnKrakenUnSubscribed: called after a successful unsubscription from a channel.

OnKranSubscriptionError: called if there is an error trying to subscribe / unsubscribe.

OnKrakenData: called every time a channel subscription has an update.