URL: wss://ws-auth.kraken.com
Once the socket is open you can subscribe to private-data channels by sending an authenticated subscribe request message.
The API client must request an authentication "token" via the following REST API endpoint "GetWebSocketsToken" to connect to WebSockets Private endpoints. The token should be used within 15 minutes of creation. The token does not expire once a connection to a WebSockets API private message (openOrders or ownTrades) is maintained.
In order to get a Websockets Token, an API Key and API Secret must be set in Kraken Options Component, the api key provided by Kraken in your account
Kraken->ApiKey = "api key";
Kraken->ApiSecret = "api secret";
Get a list of own trades, on first subscription, you get a list of latest 50 trades
SubscribeOwnTrades();
Later, you can unsubscribe from OwnTrades, calling UnSubscribeOwnTrades method
UnSubscribeOwnTrades();
Response example from 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"
]
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 to the open orders list will be sent. For status change updates, such as 'closed', the fields orderid and status will be present in the payload
SubscribeOpenOrders();
Later, you can unsubscribe from OpenOrders, calling UnSubscribeOpenOrders method
UnSubscribeOpenOrders();
Response example from 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"
]
Send a new Order to Kraken
TsgcWSKrakenOrder oKrakenOrder = new TsgcWSKrakenOrder();
oKrakenOrder->Pair = "XBT/USD";
oKrakenOrder->_Type = kosBuy;
oKrakenOrder->OrderType = kotMarket;
oKrakenOrder->Volume = 1;
AddOrder(oKrakenOrder);
List of Order parameters
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
Response example from server
{
"descr": "buy 0.01770000 XBTUSD @ limit 4000",
"event": "addOrderStatus",
"status": "ok",
"txid": "ONPNXH-KMKMU-F4MR5V"
}
Cancel order
CancelOrder("Order Id");
Response example from server
{
"event": "cancelOrderStatus",
"status": "ok"
}