Coinbase Advanced Trade Private JavaScript SDK example: submitOrderPerps.ts

Coinbase Advanced Trade Private submit order perps JavaScript example for the Siebly Coinbase 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/Coinbase/AdvancedTrade/Private/submitOrderPerps.ts

What this example covers

  • Coinbase exchange API JavaScript example.
  • Uses the Siebly Coinbase SDK package coinbase-api instead of hand-written HTTP request plumbing.
  • Source path: Coinbase/AdvancedTrade/Private/submitOrderPerps.ts.
  • Example category: Advanced Trade Private.
  • Imports SDK symbols including CBAdvancedTradeClient.
  • Calls SDK methods such as submitOrder(), generateNewOrderId().

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.
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 submitOrder() {  try {    // submit market futures order    const newOrder = await client.submitOrder({      product_id: 'BTC-USDT',      order_configuration: { market_market_ioc: { base_size: '0.001' } },      side: 'SELL',      client_order_id: client.generateNewOrderId(),    });    console.log('Result: ', newOrder);  } catch (e) {    console.error('Send new order error: ', e);  }   //} async function submitLimitOrder() {  try {    // Submit limit futures order    const limitOrder = await client.submitOrder({      product_id: 'BTC-USDT',      order_configuration: {        limit_limit_gtc: {          base_size: '0.001',          limit_price: '50000.00',        },      },      side: 'BUY',      client_order_id: client.generateNewOrderId(),    });    console.log('Limit Order Result: ', limitOrder);  } catch (e) {    console.error('Submit limit order error: ', e);  }} submitLimitOrder(); submitOrder(); 

Subscribe on Substack

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