TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sieblyio/kraken-api/llms.txt
Use this file to discover all available pages before exploring further.
WebsocketAPIClient provides a REST-like interface for sending trading commands over persistent WebSocket connections. Rather than managing raw WebSocket frames yourself, each method returns a Promise that resolves when the exchange acknowledges your request — giving you the ergonomics of async/await while benefiting from the low-latency of a long-lived WebSocket connection. Internally, the client wraps the lower-level WebsocketClient and handles authentication token retrieval, caching, and injection automatically.
All methods return Promises and can be awaited. The underlying connection is established lazily — the first call will trigger authentication and connection to
wss://ws-auth.kraken.com/v2.Constructor
WSAPIClientConfigurableOptions
| Option | Type | Default | Description |
|---|---|---|---|
attachEventListeners | boolean | true | Attaches default console.log handlers for open, reconnecting, reconnected, authenticated, and exception events. Set to false and add your own listeners via getWSClient().on(...). |
Instantiation
getWSClient()
Returns the underlying WebsocketClient instance, giving you direct access to the event emitter, connection management, and raw subscription APIs.
Methods
submitSpotOrder
Place a new Spot order over WebSocket. Supports all Kraken order types including limit, market, stop-loss, take-profit, trailing-stop, iceberg, and conditional (bracket) orders.
WSAPIAddSpotOrderResult — { order_id, cl_ord_id?, order_userref?, warnings? }
Order type. One of:
limit, market, iceberg, stop-loss, stop-loss-limit, take-profit, take-profit-limit, trailing-stop, trailing-stop-limit, settle-position.Order direction:
buy or sell.Trading pair symbol, e.g.
BTC/USD.Order quantity in base asset units.
Limit price (required for
limit, stop-loss-limit, take-profit-limit, trailing-stop-limit).How
limit_price is interpreted: static (default), pct (percentage from trigger), or quote.Trigger configuration for stop/take-profit orders. Fields:
reference (index | last), price (number), price_type (static | pct | quote).Time in force:
gtc (good till cancelled), gtd (good till date), or ioc (immediate or cancel).Client-assigned order ID (UUID recommended). Must be unique per account.
Self-trade prevention:
cancel_newest, cancel_oldest, or cancel_both.Whether fees are paid in
base or quote asset.If
true, place the order on margin.Reject the order if it would execute immediately (maker-only).
Only reduce an existing position.
ISO 8601 datetime after which the order will be rejected (RFC 3339).
If
true, validate the order parameters without submitting. Useful for dry-run testing.Conditional (bracket) order attached to this order. Fields:
order_type, limit_price, limit_price_type, trigger_price, trigger_price_type, stop_price.Visible quantity for iceberg orders.
Order quantity expressed in quote asset (cash) instead of base asset.
User-defined integer reference for the order.
amendSpotOrder
Amend the price, quantity, or post-only flag of an existing open order without cancelling and re-placing it. Prefer this over editSpotOrder for lower latency and to avoid losing queue priority where possible.
WSAPIAmendSpotOrderResult — { amend_id, order_id?, cl_ord_id?, warnings? }
Exchange-assigned order ID to amend. Provide either
order_id or cl_ord_id.Client-assigned order ID to amend. Provide either
order_id or cl_ord_id.New order quantity in base asset units.
New limit price for the order.
How the new
limit_price is interpreted: static, pct, or quote.New trigger price (for stop/take-profit orders).
Update the post-only flag.
ISO 8601 datetime deadline for the amended order.
editSpotOrder
Edit an existing order by cancelling it and re-placing it with updated parameters. The new order receives a new order_id.
WSAPIEditSpotOrderResult — { order_id, original_order_id, warnings? }
The exchange-assigned ID of the order to edit.
Trading pair symbol (must match the original order).
New order quantity.
New limit price.
New trigger settings:
reference (index | last), price, price_type.Update the post-only flag.
Validate parameters without executing the edit.
cancelSpotOrder
Cancel one or more open Spot orders by exchange order ID or client order ID.
WSAPICancelSpotOrderResult — { order_id, cl_ord_id?, warnings? }
Array of exchange-assigned order IDs to cancel.
Array of client-assigned order IDs to cancel.
Array of user reference integers to cancel.
cancelAllSpotOrders
Cancel all open Spot orders for the authenticated account in a single request.
WSAPICancelAllSpotOrdersResult — { count, warnings? }
cancelAllSpotOrdersAfter
Activate a Dead Man’s Switch that cancels all open orders after the specified timeout in seconds. Send timeout: 0 to deactivate. Re-send with a positive timeout before it fires to keep resetting the timer.
WSAPICancelAllSpotOrdersAfterResult — { currentTime, triggerTime, warnings? }
Number of seconds after which all open orders will be cancelled. Set to
0 to cancel the timer.batchSubmitSpotOrders
Submit between 2 and 15 Spot orders in a single WebSocket request. All orders in the batch share the same symbol and optional deadline.
WSAPIBatchAddSpotOrdersResult — { order_id, cl_ord_id?, order_userref?, warnings? }[]
Trading pair symbol shared by all orders in the batch, e.g.
BTC/USD.Array of 2–15 order objects. Each object takes the same fields as
WSAPIAddSpotOrderParams minus symbol (which is set at the top level).ISO 8601 deadline applied to all orders in the batch.
If
true, validate all orders without submitting any.batchCancelSpotOrders
Cancel between 2 and 50 open orders in a single WebSocket request.
WSAPIBatchCancelSpotOrdersResult — { count, warnings? }
Array of exchange-assigned order IDs to cancel (2–50 entries).
Array of client-assigned order IDs to cancel.
Using sendWSAPIRequest() Directly
If you prefer the lower-level WebsocketClient interface, you can call sendWSAPIRequest() directly on the underlying client. This approach gives you full control and is the foundation the WebsocketAPIClient methods are built on.
The
WS_KEY_MAP.spotBetaPrivateV2 key is also available if you want to route requests through the beta WebSocket endpoint. Pass it as the optional second wsKey argument to any WebsocketAPIClient method, or as the first argument to sendWSAPIRequest().Full Example
The following example demonstrates the complete Spot trading lifecycle usingWebsocketAPIClient: