Kraken Futures API

From sgcWebSockets 4.4.8 Kraken Futures API is supported

https://futures.kraken.com/

The following APIs are supported:

WebSockets Public API: connects to a public WebSocket server.
WebSockets Private API: connects to a private WebSocket server and requires an API Key and API Secret to Authenticate against server.
REST Public API: connects to a public REST server.
REST Private API: connects to a public REST server and requires an API Key and API Secret to Authenticate against server.

Kraken Futures WebSocket Public API 

Some public channels are provided without authentication. Example: you can subscribe to Ticker channel and get market data update through websocket protocol.

// Subscribe to a ticker calling SubscribeTicker method:
SubscribeTicker(['PI_XBTUSD']);


// If subscription is successful, OnKrakenFuturesSubscribed event will be called:
procedure OnKrakenFuturesSubscribed(Sender: TObject; Feed, ProductId: string);
begin
  DoLog('#subscribed: ' + Feed + ' ' + ProductId);
end;

//UnSubscribe calling UnSubscribeTicker method:
UnSubscribeTicker(['PI_XBTUSD']);

//If unsubscription is successful, OnKrakenFuturesUnSubscribed event will be called:
procedure OnKrakenFuturesUnSubscribed(Sender: TObject; Feed, ProductId: string);
begin
  DoLog('#unsubscribed: ' + Feed + ' ' + ProductId);
end;

// If there is an error while trying to subscribe / unsubscribe, OnKrakenFuturesError event will be called.
procedure OnKrakenFuturesError(Sender: TObject; Error: string);
begin
  DoLog('#error: ' + Error);
end; 

Kraken Futures WebSocket Private API 

The subscribe and unsubscribe requests to WebSocket private feeds require a signed challenge message with the user api_secret.

The challenge is obtained as is shown in Section WebSocket API Public (using the api_key).

Authenticated requests must include both the original challenge message (original_challenge) and the signed (signed_challenge) in JSON format.

In order to get a Websockets Challenge, an API Key and API Secret must be set in Kraken Options Component, the api key provided by Kraken in your account 

Example: Subscribe to AccountLog private channel.

// This subscription feed publishes account information.
SubscribeAccountLog();


// Later, you can unsubscribe from AccountLog, calling UnSubscribeAccountLog method
UnSubscribeAccountLog();


Response example from server

{  
'feed':'account_log_snapshot',
'logs':[  
{  
'id':1690,
'date':'2019-07-11T08:00:00.000Z',
'asset':'bch',
'info':'funding 
 rate change',
'booking_uid':'86fdc252-1b6e-40ec-ac1d-c7bd46ddeebf',
'margin_account':'f-bch:usd',
'old_balance':0.01215667051,
'new_balance':0.01215736653,
'old_average_entry_price':0.0,
'new_average_entry_price':0.0,
'trade_price':0.0,
'mark_price':0.0,
'realized_pnl':0.0,
'fee':0.0,
'execution':'',
'collateral':'bch',
'funding_rate':-8.7002552653e-08,
'realized_funding':6.9602e-07
}
]
} 

Kraken Futures REST Public API 

Use HTTP Protocol to get access to Public REST methods. Example: call GetOrderBook to get an snapshot of the Order Book of a Symbol.

KrakenFutures.REST_API.GetOrderBook('PI_XBTUSD'); 

Kraken Futures REST Private API 

Use the REST Private API to get access to your private account, send orders, cancel orders...

oOrder := TsgcHTTPKrakenFuturesOrder.Create;
Try
  oOrder.Side := kosfBuy;
  oOrder.Symbol := 'PI_XBTUSD';
  oOrder.OrderType := kotfMKT;
  oOrder.Size := 1;
  KrakenFutures.REST_API.SendOrder(oOrder);  
Finally
  oOrder.Free;
End; 
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

WebSocket Send File .NET
OpenSSL Perfect Forward Secrecy

Related Posts