Skip to content

Account access and balances ​

Public market data needs no API credentials. Private account queries and trading require credentials with the relevant permissions for the chosen product.

Configure credentials ​

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;
}

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

export { client };

Supply API credentials through protected server-side environment variables or a secret manager. Keep them out of source files and browser bundles. Creating a client alone does not verify access.

Verify account access ​

The following example reads balances from a live Kraken Spot account. Use a Spot API key with permission to query funds. It does not place orders or transfer funds.

For local development, create a private .env file with your credentials. The values here are fictitious:

dotenv
KRAKEN_API_KEY=kraken_example_key_7e2a9c # Your Spot API key
KRAKEN_API_SECRET=ZXhhbXBsZS1vbmx5LW5vdC1hLXJlYWwta2V5 # Your base64 API secret

Exclude .env from version control.

Save this plain JavaScript example as account.mjs:

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

async function main() {
  const apiKey = process.env.KRAKEN_API_KEY;
  const apiSecret = process.env.KRAKEN_API_SECRET;
  if (!apiKey || !apiSecret) {
    throw new Error('Set KRAKEN_API_KEY and KRAKEN_API_SECRET.');
  }

  const client = new SpotClient({ apiKey, apiSecret });
  const response = await client.getAccountBalance();
  console.log('Account access verified.');
  console.log('Returned asset balances:', Object.keys(response.result).length);
}

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

With Node.js 24, run:

sh
node --env-file=.env account.mjs

If the variables are already supplied by your server environment, run node account.mjs. A successful response prints Account access verified. and the number of returned balances. The balances themselves are available in response.result.

Signing and permissions ​

The SDK signs requests and supplies the nonce. Keep requests using one API key coordinated across processes so they do not arrive with out-of-order nonces. Use separate credentials for independently running services where appropriate.

Match API permissions and IP restrictions to the operation. Private Spot WebSocket subscriptions also require the API key's WebSocket access permission; the SDK obtains and supplies the WebSocket token automatically.

Private account updates · Order validation · Kraken authentication documentation

Built by Siebly. Open source SDKs for exchange APIs.