API Kraken | WebSockets Private API

Connessione

URL: wss://ws-auth.kraken.com (v1) o wss://ws-auth.kraken.com/v2 (v2, raccomandato)

Il componente ora supporta WebSocket API v2 tramite la proprietà Version (predefinito: 2).

 

Una volta aperto il socket, è possibile iscriversi ai canali di dati privati inviando un messaggio di richiesta di iscrizione autenticato.

 

Autenticazione

Il client API deve richiedere un "token" di autenticazione tramite il seguente endpoint REST API "GetWebSocketsToken" per connettersi agli endpoint privati WebSockets. Il token deve essere utilizzato entro 15 minuti dalla creazione. Il token non scade finché viene mantenuta una connessione a un messaggio privato dell'API WebSockets (openOrders o ownTrades).

Per ottenere un Token WebSockets, è necessario impostare una chiave API e un segreto API nel componente Kraken Options; la chiave API è fornita da Kraken nel proprio account

  
Kraken.ApiKey := 'api key';
Kraken.ApiSecret := 'api secret';

Metodi

OwnTrades

Ottenere un elenco delle proprie transazioni; alla prima sottoscrizione si ottiene un elenco delle ultime 50 transazioni

  
SubscribeOwnTrades();

In seguito, è possibile annullare la sottoscrizione da OwnTrades chiamando il metodo UnSubscribeOwnTrades

  
UnSubscribeOwnTrades();

Esempio di risposta dal server


[
  [
    {
      "TDLH43-DVQXD-2KHVYY": {
        "cost": "1000000.00000",
        "fee": "600.00000",
        "margin": "0.00000",
        "ordertxid": "TDLH43-DVQXD-2KHVYY",
        "ordertype": "limit",
        "pair": "XBT/EUR",
        "postxid": "OGTT3Y-C6I3P-XRI6HX",
        "price": "100000.00000",
        "time": "1560520332.914664",
        "type": "buy",
        "vol": "1000000000.00000000"
      }
    }
  ],
  "ownTrades"
]

Ordini aperti

Feed per visualizzare tutti gli ordini aperti appartenenti all'utente autenticato tramite chiave API. Lo snapshot iniziale fornirà l'elenco di tutti gli ordini aperti e successivamente verranno inviati gli aggiornamenti all'elenco degli ordini aperti. Per gli aggiornamenti di cambio di stato, come 'closed', i campi orderid e status saranno presenti nel payload

  
SubscribeOpenOrders();

Successivamente è possibile annullare la sottoscrizione da OpenOrders chiamando il metodo UnSubscribeOpenOrders

  
UnSubscribeOpenOrders();

Esempio di risposta dal server


[
  [
    {
      "OGTT3Y-C6I3P-XRI6HX": {
        "cost": "0.00000",
        "descr": {
          "close": "",
          "leverage": "0:1",
          "order": "sell 0.00001000 XBT/EUR @ limit 9.00000 with 0:1 leverage",
          "ordertype": "limit",
          "pair": "XBT/EUR",
          "price": "9.00000",
          "price2": "0.00000",
          "type": "sell"
        },
        "expiretm": "0.000000",
        "fee": "0.00000",
        "limitprice": "9.00000",
        "misc": "",
        "oflags": "fcib",
        "opentm": "0.000000",
        "price": "9.00000",
        "refid": "OKIVMP-5GVZN-Z2D2UA",
        "starttm": "0.000000",
        "status": "open",
        "stopprice": "0.000000",
        "userref": 0,
        "vol": "0.00001000",
        "vol_exec": "0.00000000"
      }
    }
  ],
  "openOrders"
]

Aggiungi Ordine

Invia un nuovo Ordine a Kraken

  
oKrakenOrder := TsgcWSKrakenOrder.Create;
oKrakenOrder.Pair := 'XBT/USD';
oKrakenOrder._Type := kosBuy;
oKrakenOrder.OrderType := kotMarket;
oKrakenOrder.Volume := 1;
AddOrder(oKrakenOrder);

Elenco dei parametri dell'Order


pair = asset pair
type = type of order (buy/sell)
ordertype = order type:
    market
    limit (price = limit price)
    stop-loss (price = stop loss price)
    take-profit (price = take profit price)
    stop-loss-profit (price = stop loss price, price2 = take profit price)
    stop-loss-profit-limit (price = stop loss price, price2 = take profit price)
    stop-loss-limit (price = stop loss trigger price, price2 = triggered limit price)
    take-profit-limit (price = take profit trigger price, price2 = triggered limit price)
    trailing-stop (price = trailing stop offset)
    trailing-stop-limit (price = trailing stop offset, price2 = triggered limit offset)
    stop-loss-and-limit (price = stop loss price, price2 = limit price)
    settle-position
price = price (optional.  dependent upon ordertype)
price2 = secondary price (optional.  dependent upon ordertype)
volume = order volume in lots
leverage = amount of leverage desired (optional.  default = none)
oflags = comma delimited list of order flags (optional):
    viqc = volume in quote currency (not available for leveraged orders)
    fcib = prefer fee in base currency
    fciq = prefer fee in quote currency
    nompp = no market price protection
    post = post only order (available when ordertype = limit)
starttm = scheduled start time (optional):
    0 = now (default)
    +<n> = schedule start time <n> seconds from now
    <n> = unix timestamp of start time
expiretm = expiration time (optional):
    0 = no expiration (default)
    +<n> = expire <n> seconds from now
    <n> = unix timestamp of expiration time
userref = user reference id.  32-bit signed number.  (optional)
validate = validate inputs only.  do not submit order (optional)
optional closing order to add to system when order gets filled:
    close[ordertype] = order type
    close[price] = price
    close[price2] = secondary price

Esempio di risposta dal server


{
  "descr": "buy 0.01770000 XBTUSD @ limit 4000",
  "event": "addOrderStatus",
  "status": "ok",
  "txid": "ONPNXH-KMKMU-F4MR5V"
}

Annulla Ordine

Annullamento ordine

  
CancelOrder('Order Id');

Esempio di risposta dal server


{
  "event": "cancelOrderStatus",
  "status": "ok"
}