Robust error handling is a prerequisite for any reliable trading integration. 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.
@siebly/kraken-api SDK surfaces errors through two distinct channels depending on how you interact with the API: REST clients throw (or reject) on failure, and the WebsocketClient emits named events for connection-level issues. Understanding both patterns — and combining them correctly — means your system responds precisely to what went wrong, instead of silently failing at the worst possible moment.
REST API errors
All REST client methods (SpotClient, DerivativesClient, etc.) return promises. When a request fails — whether due to a network problem, an invalid parameter, or an exchange-side rejection — the SDK throws a structured error object. You can intercept it with a try/catch block or a .catch() handler.
The SDK’s parseException method in BaseRestClient normalises HTTP error responses into a consistent shape before throwing:
Wrapping orders in try/catch
The cleanest pattern for order submission is atry/catch around the awaited call, with structured logging of the error body so you have the exchange’s reason alongside your own context:
.catch() inline for fire-and-forget flows:
Enabling HTTP trace logging
For low-level debugging, set theKRAKENTRACE environment variable before starting your process. The SDK will then log every outgoing request and incoming response via axios interceptors:
WebSocket errors
TheWebsocketClient is event-driven. Rather than throwing exceptions, it emits named events you register handlers for. The two most important events for error handling are exception and the reconnect pair reconnecting / reconnected.
Listening to the exception event
The exception event fires when the SDK encounters an unexpected condition on a WebSocket connection — such as a protocol error, a failed authentication attempt, or an unhandled message format:
Handling reconnects
The SDK monitors connections with heartbeats. When a disconnect is detected, it automatically tears down the stale connection and opens a new one, re-authenticating and re-subscribing to all previously active topics. Your application is informed at each stage:| Event | When it fires | Recommended action |
|---|---|---|
reconnecting | Disconnect detected, retry in progress | Pause order management |
reconnected | Connection restored and subscriptions synced | Backfill via REST, then resume |
reconnecting event as an unrecoverable error. WebSocket connections can drop during periods of high market volatility or routine network interruptions. The SDK handles re-establishment; your responsibility is to resync application state once the connection is restored.
Network and timeout errors
The SDK sends REST requests viaaxios. By default, requests time out after 5 minutes. You can reduce this — or add proxy support — via the networkOptions second argument accepted by every REST client constructor:
.catch() or try/catch will capture. The err.request property will be set but err.response will be undefined, indicating the request left the client but no reply arrived.
Common errors FAQ
"Invalid API key" or "EAPI:Invalid key"
"Invalid API key" or "EAPI:Invalid key"
This means the API key supplied does not match what Kraken has on record, or it was created for the wrong product group.
- Double-check that the key and secret are copied correctly — trailing whitespace is a common culprit.
- Confirm you are using Spot credentials with
SpotClientand Futures credentials withDerivativesClient. Keys are not interchangeable across products. - Verify the key is active and has not been revoked in your Kraken account settings.
"Permission denied" or "EAPI:Invalid permissions"
"Permission denied" or "EAPI:Invalid permissions"
Your API key is valid but lacks the permission required for the operation you attempted.
- Trading endpoints require the Orders and trades permission.
- Account data endpoints require the Query funds or Query orders permissions.
- Withdrawal endpoints require the Withdraw funds permission — only enable this if your use case explicitly requires it.
"NONCE too small" or nonce errors on parallel requests
"NONCE too small" or nonce errors on parallel requests
Kraken’s Spot REST API uses a monotonically increasing nonce per API key to prevent replay attacks. If two requests are dispatched simultaneously using the same credentials, one nonce may arrive at Kraken before the other but with a lower value.
- Avoid firing multiple concurrent authenticated requests from different code paths sharing the same
SpotClientinstance if ordering is critical. - The SDK’s internal nonce generator handles sequential requests correctly; the issue arises when you deliberately parallelise private calls.
- For high-throughput scenarios, use batch endpoints (
submitBatchOrders) instead of multiple concurrent single-order calls.
Connection closed unexpectedly
Connection closed unexpectedly
An unexpected close fires the
close event. The SDK will automatically attempt to reconnect and re-subscribe. You do not need to manually re-instantiate the client.Listen for reconnecting to know a retry is in progress, and reconnected to know recovery is complete. If reconnection is taking longer than expected, check Kraken’s status page for ongoing incidents.