Example: getOrders.ts

Static snapshot for Coinbase/AdvancedTrade/Private/getOrders.ts.

Example Path

Coinbase/AdvancedTrade/Private/getOrders.ts

Source Link

Repository source: https://github.com/sieblyio/crypto-api-examples/blob/master/examples/Coinbase/AdvancedTrade/Private/getOrders.ts

Code Snapshot

import { CBAdvancedTradeClient } from 'coinbase-api';

// initialise the client
/**
 *
 * You can add both ED25519 and ECDSA keys, client will recognize both types of keys
 *
 * ECDSA:
 *
 * {
 *   apiKey: 'organizations/your_org_id/apiKeys/your_api_key_id',
 *   apiSecret:
 *     '-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIPT/TTZPxw0kDGvpuCENJp9A4/2INAt9/QKKfyidTWM8oAoGCCqGSM49\nAwEHoUQDQgAEd+cnxrKl536ly5eYBi+8dvXt1MJXYRo+/v38h9HrFKVGBRndU9DY\npV357xIfqeJEzb/MBuk3EW8cG9RTrYBwjg==\n-----END EC PRIVATE KEY-----\n',
 * }
 *
 * ED25519:
 * {
 *   apiKey: 'your-api-key-id',
 *   apiSecret: 'yourExampleApiSecretEd25519Version==',
 * }
 *
 *
 */
const client = new CBAdvancedTradeClient({
  apiKey: process.env.API_KEY_NAME || 'insert_api_key_here',
  apiSecret: process.env.API_PRIVATE_KEY || 'insert_api_secret_here',
});

async function getOrders() {
  try {
    // Get all orders
    const orders = await client.getOrders({ limit: 5 });
    console.log('Orders: ', orders);

    // Get order details
    if (orders.orders.length > 0) {
      const orderId = orders.orders[0].order_id;
      const orderDetails = await client.getOrder({ order_id: orderId });
      console.log('Order Details: ', orderDetails);
    }
  } catch (e) {
    console.error('Error: ', e);
  }
}

getOrders();

This is a static, crawlable snapshot. The interactive app loads after JavaScript starts and can refresh live data.