Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/coinbase-api/llms.txt

Use this file to discover all available pages before exploring further.

The coinbase-api npm package is a professional, production-ready Node.js SDK that provides a unified interface to every Coinbase REST API and WebSocket feed. It is actively maintained, battle-tested in live trading environments, and ships with full TypeScript declarations so your editor can autocomplete every request parameter and response field.

Why coinbase-api?

Coinbase operates six distinct API surfaces — each targeting a different user type and product. Rather than juggling six separate HTTP wrappers, coinbase-api gives you a single, consistent package with dedicated clients for each platform:
  • Strongly typed — every request and response is modelled in TypeScript.
  • Promise-driven — all REST methods return native Promises; async/await just works.
  • Dual module output — ships compiled ESM and CJS, so it works in any Node.js project regardless of "type" field.
  • Browser bundle — a webpack build is included for frontend usage.
  • Proxy support — powered by axios, so standard proxy configuration applies without any extra wrapping.
  • Automatic key detection — pass ECDSA or ED25519 private keys; the SDK detects the format and signs correctly every time.
  • Robust WebSocket layer — auto-reconnect, resubscribe on reconnect, configurable heartbeats, and event-driven message dispatch.
Upcoming change: As part of the Siebly.io brand, this SDK will soon be hosted under the Siebly.io GitHub organisation. The migration is seamless and requires no changes from users.

REST Clients

Each Coinbase product group has its own REST client. Import only what you need.

CBAdvancedTradeClient

Coinbase’s modern retail and algorithmic trading platform. Supports spot and futures orders, order management, portfolios, and product data.

CBAppClient

Consumer-facing Coinbase mobile and web app APIs. Manage wallets, send/receive funds, and query transaction history programmatically.

CBExchangeClient

The professional Coinbase Exchange (formerly Coinbase Pro) REST API. Full order book access, fills, accounts, and payment methods.

CBInternationalClient

Institutional cross-border trading via the Coinbase International Exchange. Designed for large-volume, multi-currency institutional flows.

CBPrimeClient

Institutional custody and trading through Coinbase Prime. Portfolio management, allocations, and wallet operations for institutions.

CBCommerceClient

Accept cryptocurrency payments via Coinbase Commerce. Create charges, manage invoices, and handle on-chain payment events.

WebSocket Client

A single WebsocketClient class handles every Coinbase WebSocket feed — public market data and private user data alike. You pass a WsKey string to route subscriptions to the correct upstream connection, and the client manages keep-alive pings, reconnection, and resubscription automatically.
import { WebsocketClient } from 'coinbase-api';

const ws = new WebsocketClient({
  apiKey: process.env.API_KEY_NAME,
  apiSecret: process.env.API_PRIVATE_KEY,
});

ws.on('update', (data) => console.log('market data:', data));
ws.on('reconnected', (data) => console.log('reconnected:', data.wsKey));

// Subscribe to BTC-USD ticker on Advanced Trade public feed
ws.subscribe(
  { topic: 'ticker', payload: { product_ids: ['BTC-USD'] } },
  'advTradeMarketData',
);
Key WebSocket features:
  • Auto-reconnect — dropped connections are restored automatically; a reconnected event fires when live again.
  • Resubscribe on reconnect — all active subscriptions are replayed after reconnection with no extra code.
  • Event-driven — listen to open, update, response, reconnect, reconnected, close, and exception events.
  • Public & private streams — unauthenticated market data and authenticated user data streams across all platforms.

TypeScript Support

The SDK is written in TypeScript and exports type declarations for the vast majority of API request parameters and response shapes. You get full IntelliSense support in VS Code and other editors without any additional @types package.
import { CBAdvancedTradeClient } from 'coinbase-api';
import type { SubmitAdvTradeOrderRequest } from 'coinbase-api';

const client = new CBAdvancedTradeClient({
  apiKey: process.env.API_KEY_NAME!,
  apiSecret: process.env.API_PRIVATE_KEY!,
});

// `order` is fully typed — TypeScript will catch missing required fields
const order: SubmitAdvTradeOrderRequest = {
  product_id: 'BTC-USDT',
  side: 'BUY',
  client_order_id: client.generateNewOrderId(),
  order_configuration: {
    limit_limit_gtc: { base_size: '0.01', limit_price: '60000.00' },
  },
};

const result = await client.submitOrder(order);

Exported Types & Utilities

The package exports the following public symbols from coinbase-api. These cover every client class, configuration type, and WebSocket utility you need:
ExportKindDescription
CBAdvancedTradeClientClassREST client for the Advanced Trade API
CBAppClientClassREST client for the Coinbase App API
CBExchangeClientClassREST client for the Exchange API
CBInternationalClientClassREST client for the International Exchange API
CBPrimeClientClassREST client for the Prime API
CBCommerceClientClassREST client for the Commerce API
WebsocketClientClassUnified WebSocket client for all feeds
WS_KEY_MAPConstEnum-like map of all valid WebSocket key strings (e.g. advTradeMarketData, advTradeUserData, exchangeMarketData)
WsKeyTypeUnion of all valid WsKey string literals derived from WS_KEY_MAP
WsTopicRequestInterfaceStructured subscribe/unsubscribe request object { topic: string; payload?: any }
WSConnectedResultInterfaceResult returned when a WebSocket connection is established: { wsKey: string }
RestClientOptionsInterfaceConfiguration object accepted by all REST client constructors (credentials, sandbox, keep-alive, etc.)
DefaultLoggerConstDefault logger object with trace, info, and error methods; spread and override to customise logging
import {
  CBAdvancedTradeClient,
  WebsocketClient,
  WS_KEY_MAP,
  DefaultLogger,
} from 'coinbase-api';
import type {
  WsKey,
  WsTopicRequest,
  WSConnectedResult,
  RestClientOptions,
} from 'coinbase-api';

// Use WS_KEY_MAP like an enum to avoid typos in WsKey strings
const myKey: WsKey = WS_KEY_MAP.advTradeMarketData; // 'advTradeMarketData'

// Customise the logger — suppress noisy trace messages
const logger = {
  ...DefaultLogger,
  trace: (...params: any[]) => {
    // Suppress heartbeat noise
    if (['Sending ping', 'Received pong, clearing pong timer'].includes(params[0])) return;
    console.log('trace', params);
  },
};

const options: RestClientOptions = {
  apiKey: process.env.API_KEY_NAME!,
  apiSecret: process.env.API_PRIVATE_KEY!,
};

const ws = new WebsocketClient(options, logger);

Authentication

coinbase-api supports two authentication schemes depending on which client you use:
  • JWT (ECDSA / ED25519)CBAdvancedTradeClient and CBAppClient use short-lived JWTs signed with your CDP API private key. Both key formats are detected automatically.
  • API Key + Secret + PassphraseCBExchangeClient, CBInternationalClient, and CBPrimeClient use HMAC-signed requests with an additional passphrase.
See the Authentication guide for full configuration details.

Module Formats & Browser Usage

The package ships with both an ESM build (dist/mjs/) and a CommonJS build (dist/cjs/). Node.js will select the right one automatically based on your project’s module system.
// ESM (TypeScript, .mjs, or "type": "module" projects)
import { CBAdvancedTradeClient } from 'coinbase-api';

// CJS (require-based projects)
const { CBAdvancedTradeClient } = require('coinbase-api');
For browser or frontend bundling, run npm run build && npm run pack inside a clone of the repository. The resulting webpack bundle is placed in dist/ and can be loaded directly in a browser.

Proxy Support

Because the SDK uses axios under the hood, you can configure HTTP proxies via the standard axios proxy options or by setting the HTTP_PROXY / HTTPS_PROXY environment variables — no extra configuration needed on the RestClientOptions level.

Next Steps

Quickstart

Install the SDK and make your first API call in under five minutes.

Authentication

Configure credentials for JWT-based and passphrase-based clients.

Build docs developers (and LLMs) love