Coinbase TypeScript SDK example: cb-exchange-private.ts

Coinbase Institutional CBExchange REST cb exchange private example for the Siebly Coinbase SDK, with TypeScript source for exchange REST API and WebSocket integration, setup, and production SDK docs.

What This Example Covers

  • Coinbase REST API example in TypeScript.
  • Uses the Siebly Coinbase SDK package coinbase-api instead of hand-written HTTP request plumbing.
  • Source path: Coinbase/Institutional/CBExchange/Rest/cb-exchange-private.ts.
  • Example category: Institutional CBExchange REST.
  • Imports SDK symbols including CBExchangeClient.
  • Calls SDK methods such as getOrders(), getOrder(), cancelOrder().

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.

Example Path

Coinbase/Institutional/CBExchange/Rest/cb-exchange-private.ts

Source Link

Repository source: https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Coinbase/Institutional/CBExchange/Rest/cb-exchange-private.ts

Related SDK Docs

Example Source

import { CBExchangeClient } from 'coinbase-api';

// Initialize the client, you can pass in api keys here if you have them but they are not required for public endpoints
const client = new CBExchangeClient({
  apiKey: 'yourAPIKeyHere',
  apiSecret: 'yourAPISecretHere',
  //This is the passphrase you provided when creating this API key. NOT your account password.
  apiPassphrase: 'yourAPIPassPhraseHere',

  // Optional, connect to sandbox instead: https://public-sandbox.exchange.coinbase.com/apikeys
  // useSandbox: true,
});

async function privateExchangeCalls() {
  try {
    const orders = await client.getOrders();
    console.log('Orders: ', orders);

    const order = await client.getOrder({
      order_id: '0c892cb3-2824-4662-8be3-99c8e879f606',
      market_type: 'market',
    });
    console.log('Order: ', order);

    const cancelOrderResult = await client.cancelOrder({
      order_id: '0c892cb3-2824-4662-8be3-99c8e879f606',
      product_id: 'BTC-GBP',
    });
    console.log('cancelOrder result: ', cancelOrderResult);
  } catch (e) {
    console.error('Error: ', e);
  }
}

privateExchangeCalls();