Skip to content

Order management ​

Use SpotClient to read balances, prepare and submit orders, and cancel open orders. Keep the private execution stream connected to follow order changes and fills.

Read balances and existing orders ​

Start with the authenticated account example. getAccountBalance() returns balances keyed by asset in result. getOpenOrders() provides an initial open-order snapshot. Use the query permissions required by those methods before adding trading permissions.

Prepare an order without placing it ​

Kraken Spot has no public testnet, and the Futures demo environment has been retired. This example uses Spot's validate: true option: Kraken checks the request without submitting an order to the market.

Validation does not simulate fills or predict the price, liquidity or account state available for a later live order.

Configure the request ​

Use the authentication setup with a Spot key permitted to create orders. Choose a pair, price and volume suitable for your account, using getAssetPairs() for current precision and minimums.

Add a price and volume to your private .env file. These are illustrative, not a trading recommendation:

dotenv
KRAKEN_ORDER_PRICE=50000 # Limit price in USD for XBTUSD
KRAKEN_ORDER_VOLUME=0.0002 # Amount of BTC

Save this as validate-order.ts in a TypeScript project:

ts
import { SpotClient } from '@siebly/kraken-api';

function requiredEnvVar(name: string) {
  const value = process.env[name];
  if (!value) {
    throw new Error(`Set ${name}.`);
  }
  return value;
}

async function main() {
  const client = new SpotClient({
    apiKey: requiredEnvVar('KRAKEN_API_KEY'),
    apiSecret: requiredEnvVar('KRAKEN_API_SECRET'),
  });

  // Kraken validates this request without submitting an order to the market.
  const response = await client.submitOrder({
    pair: 'XBTUSD',
    type: 'buy',
    ordertype: 'limit',
    price: requiredEnvVar('KRAKEN_ORDER_PRICE'),
    volume: requiredEnvVar('KRAKEN_ORDER_VOLUME'),
    validate: true,
  });
  console.log('Validation result:', response.result);
}

main().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

Run it with Node.js 24:

sh
node --env-file=.env validate-order.ts

A successful response prints the validation result. Validation does not create an order to query or cancel.

Submit and manage a live order ​

For a live order, submitOrder() accepts the same parameters with validate omitted or false. That sends an actual order to Kraken's production market. Connect the private execution stream before submitting and confirm the subscription. Save the exchange-returned result.txid values and use matching execution events to track order changes and fills. Use cancelOrder({ txid }) to request cancellation.

A cancellation request can race with a fill. Follow private execution updates to determine the resulting state. Subscribe to balance updates too when your application needs them. A successful REST response can provide useful immediate information, but it does not replace ongoing account events.

If the REST response and private events leave an outcome unclear, use getOrders({ txid }) for a targeted read. If no ID is available, inspect open orders, closed orders and executions before retrying. An absent or delayed response is not proof that the order was rejected. REST reads are a recovery tool here, not a follow-up to every order. See Production usage.

Built by Siebly. Open source SDKs for exchange APIs.