Kraken Spot Private JavaScript SDK example: account.ts

Kraken Spot Private account JavaScript example for the Siebly Kraken SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Kraken/Spot/Private/account.ts

What this example covers

  • Kraken exchange API JavaScript example.
  • Uses the Siebly Kraken SDK package @siebly/kraken-api instead of hand-written HTTP request plumbing.
  • Source path: Kraken/Spot/Private/account.ts.
  • Example category: Spot Private.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getAccountBalance(), getExtendedBalance(), getTradeBalance(), getLedgers(), getLedgersInfo(), getTradingVolume().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • For private or order-management examples, keep credentials in environment variables or a secret manager. Use read-only keys where possible, and check the execution mode reference before any exchange write path can run.
  • Open the repository source when you need the latest committed version: GitHub source file.
/* eslint-disable @typescript-eslint/no-unused-vars */import { SpotClient } from '@siebly/kraken-api'; // This example shows how to call Kraken API endpoint with either node.js,// javascript (js) or typescript (ts) with the npm module "@siebly/kraken-api" for Kraken exchange// for ACCOUNT INFORMATION // initialise the client/** * * Kraken API uses API Key and Private Key (base64 encoded) * * Example: * { *   apiKey: 'your-api-key', *   apiSecret: 'your-base64-encoded-private-key', * } * * API Key Permissions Required: * - Funds permissions - Query * - Data - Query ledger entries * */const client = new SpotClient({  apiKey: process.env.API_SPOT_KEY || 'insertApiKeyHere',  apiSecret: process.env.API_SPOT_SECRET || 'insertApiSecretHere',}); async function getAccountBalance() {  try {    // Get all cash balances (net of pending withdrawals)    const balances = await client.getAccountBalance();    console.log('Account Balances: ', JSON.stringify(balances, null, 2));     // Note: Staking/Earn assets may have these extensions:    // .B - balances in new yield-bearing products    // .F - balances earning automatically in Kraken Rewards    // .T - tokenized assets  } catch (e) {    console.error('Get account balance error: ', e);  }} async function getExtendedBalance() {  try {    // Get extended balances including credits and held amounts    // Available balance = balance + credit - credit_used - hold_trade    const extendedBalances = await client.getExtendedBalance();    console.log(      'Extended Balances: ',      JSON.stringify(extendedBalances, null, 2),    );  } catch (e) {    console.error('Get extended balance error: ', e);  }} async function getTradeBalance() {  try {    // Get trade balance summary (margin info)    const tradeBalance = await client.getTradeBalance();    console.log('Trade Balance: ', JSON.stringify(tradeBalance, null, 2));     // Response includes:    // - eb: equivalent balance    // - tb: trade balance    // - m: margin amount    // - n: unrealized P&L    // - e: equity    // - mf: free margin  } catch (e) {    console.error('Get trade balance error: ', e);  }} async function getLedgers() {  try {    // Query specific ledger entries by ID    const ledgers = await client.getLedgers({      id: 'LUI2RA-CJFLB-EN5I4P,L2QE42-IGSZ3-WEVTLK',      trades: false,    });    console.log('Ledger Entries: ', JSON.stringify(ledgers, null, 2));     // Ledger entry types include:    // - trade, deposit, withdrawal, transfer, margin    // - adjustment, rollover, spend, receive, settled    // - credit, staking, reward, dividend, sale, conversion  } catch (e) {    console.error('Query ledgers error: ', e);  }} async function getLedgersInfo() {  try {    // Get ledger info with filters (returns 50 most recent by default)    const ledgersInfo = await client.getLedgersInfo({      asset: 'XBT', // Filter by asset      type: 'deposit', // Filter by type    });    console.log('Ledgers Info: ', JSON.stringify(ledgersInfo, null, 2));  } catch (e) {    console.error('Get ledgers info error: ', e);  }} async function getTradingVolume() {  try {    // Get 30-day USD trading volume and fee schedule    const tradingVolume = await client.getTradingVolume({      pair: 'XBTUSD,ETHUSD',    });    console.log('Trading Volume: ', JSON.stringify(tradingVolume, null, 2));     // Response includes:    // - currency: volume currency    // - volume: current trading volume    // - fees: fee schedule by pair    // - fees_maker: maker fee schedule  } catch (e) {    console.error('Get trading volume error: ', e);  }} // Uncomment the function you want to test: getAccountBalance();// getExtendedBalance();// getTradeBalance();// getLedgers();// getLedgersInfo();// getTradingVolume(); 

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.