Kraken Spot Public JavaScript SDK example: marketData.ts

Kraken Spot Public market data JavaScript example. Read the source code, review its SDK calls, and browse related exchange integration examples.

This example uses @siebly/kraken-api, the JavaScript and TypeScript SDK for Kraken. Install it with npm install @siebly/kraken-api.

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

examples/Kraken/Spot/Public/marketData.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/Public/marketData.ts.
  • Example category: Spot Public.
  • Imports SDK symbols including SpotClient.
  • Calls SDK methods such as getServerTime(), getSystemStatus(), getAssetInfo(), getAssetPairs(), getTicker(), getOrderBook(), getCandles(), getRecentTrades(), getRecentSpreads().

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.
  • Open the repository source when you need the latest committed version: GitHub source file.
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 PUBLIC MARKET DATA that requires no authentication // you can initialise public client without api keys as public calls do not require authconst client = new SpotClient(); async function publicCalls() {  try {    // Get server time    const serverTime = await client.getServerTime();    console.log('Server Time: ', serverTime);     // Get system status    const systemStatus = await client.getSystemStatus();    console.log('System Status: ', systemStatus);     // Get asset info    const assetInfo = await client.getAssetInfo({      asset: 'XBT,ETH',    });    console.log('Asset Info: ', assetInfo);     // Get tradable asset pairs    const assetPairs = await client.getAssetPairs({      pair: 'XBTUSD,ETHUSD',    });    console.log('Asset Pairs: ', assetPairs);     // Get ticker information    const ticker = await client.getTicker({      pair: 'XBTUSD',    });    console.log('Ticker: ', ticker);     // Get order book    const orderBook = await client.getOrderBook({      pair: 'XBTUSD',      count: 10,    });    console.log('Order Book: ', orderBook);     // Get OHLC data (candles)    const candles = await client.getCandles({      pair: 'XBTUSD',      interval: 60, // 1 minute    });    console.log('OHLC Candles: ', candles);     // Get recent trades    const recentTrades = await client.getRecentTrades({      pair: 'XBTUSD',      count: 10,    });    console.log('Recent Trades: ', recentTrades);     // Get recent spreads    const recentSpreads = await client.getRecentSpreads({      pair: 'XBTUSD',    });    console.log('Recent Spreads: ', recentSpreads);  } catch (e) {    console.error('Error: ', e);  }} publicCalls(); 

Subscribe on Substack

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