Kraken Derivatives Private JavaScript SDK example: submitOrder.ts

Kraken Derivatives Private submit order 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/Derivatives/Private/submitOrder.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/Derivatives/Private/submitOrder.ts.
  • Example category: Derivatives Private.
  • Imports SDK symbols including DerivativesClient.
  • Calls SDK methods such as submitOrder(), generateNewOrderID(), batchOrderManagement().

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 { DerivativesClient } 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 FUTURES ORDER MANAGEMENT // initialise the client/** * * Kraken Futures API uses API Key and API Secret * * Example: * { *   apiKey: 'your-api-key', *   apiSecret: 'your-api-secret', * } * * API Key Permissions Required: Orders and trades - Create & modify orders * */const client = new DerivativesClient({  apiKey: process.env.API_FUTURES_KEY || 'insertApiKeyHere',  apiSecret: process.env.API_FUTURES_SECRET || 'insertApiSecretHere',}); async function submitLimitOrder() {  try {    // Submit limit order for Futures    const limitOrder = await client.submitOrder({      orderType: 'lmt',      symbol: 'PF_ETHUSD', // Perpetual ETH/USD      side: 'buy',      size: 0.01, // Contract size      limitPrice: 1000,      cliOrdId: client.generateNewOrderID(),    });    console.log('Limit Order Result: ', JSON.stringify(limitOrder, null, 2));     // Response includes:    // - status: placed, partiallyFilled, filled, or rejection reason    // - order_id: Unique order identifier    // - orderEvents: Array of order events (PLACE, EXECUTE, etc.)  } catch (e) {    console.error('Submit limit order error: ', e);  }} async function submitMarketOrder() {  try {    // Submit market order (IOC with 1% price protection)    const marketOrder = await client.submitOrder({      orderType: 'mkt',      symbol: 'PF_ETHUSD',      side: 'sell', // or "buy"      size: 0.01,    });    console.log('Market Order Result: ', JSON.stringify(marketOrder, null, 2));  } catch (e) {    console.error('Submit market order error: ', e);  }} async function submitPostOnlyOrder() {  try {    // Submit post-only order (maker-only)    const postOrder = await client.submitOrder({      orderType: 'post',      symbol: 'PF_ETHUSD',      side: 'buy',      size: 0.01,      limitPrice: 1000,      cliOrdId: client.generateNewOrderID(),    });    console.log('Post-Only Order Result: ', JSON.stringify(postOrder, null, 2));  } catch (e) {    console.error('Submit post-only order error: ', e);  }} async function submitReduceOnlyOrder() {  try {    // Submit reduce-only order (only closes position, won't open new)    const reduceOnlyOrder = await client.submitOrder({      orderType: 'lmt',      symbol: 'PF_ETHUSD',      side: 'sell',      size: 1,      limitPrice: 1000,      reduceOnly: true, // Only reduce existing position    });    console.log(      'Reduce-Only Order Result: ',      JSON.stringify(reduceOnlyOrder, null, 2),    );  } catch (e) {    console.error('Submit reduce-only order error: ', e);  }} async function batchOrderSubmit() {  try {    // Send, edit, and cancel orders in a single batch request    const batchResult = await client.batchOrderManagement({      json: {        batchOrder: [          // Send new order          {            order: 'send',            order_tag: 'order-1', // Tag to map responses            orderType: 'lmt',            symbol: 'PF_ETHUSD',            side: 'buy',            size: 0.01,            limitPrice: 1000,            cliOrdId: client.generateNewOrderID(),          },          // Send another order          {            order: 'send',            order_tag: 'order-2',            orderType: 'lmt',            symbol: 'PF_ETHUSD',            side: 'buy',            size: 0.01,            limitPrice: 1100,          },        ],      },    });    console.log('Batch Order Result: ', JSON.stringify(batchResult, null, 2));     // Response includes batchStatus array with results for each order    // - status: placed, edited, cancelled, or rejection reason    // - order_tag: Maps back to your request  } catch (e) {    console.error('Batch order management error: ', e);  }} // Uncomment the function you want to test: // submitLimitOrder();// submitMarketOrder();// submitPostOnlyOrder();// submitReduceOnlyOrder();//batchOrderSubmit(); 

Subscribe on Substack

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