Coinbase API in Node.js: App, Advanced Trade and Exchange APIs with the Coinbase SDK

"The Coinbase API" is really several APIs with different hosts, keys and response shapes. Three of them serve public market data without a key, and picking the right one first saves a lot of rework. This guide calls all three from Node.js with coinbase-api, an open-source Coinbase SDK for Node.js and TypeScript that has one client class per Coinbase API.

Which Coinbase API to use

APIBase URLGood forSDK client
Coinbase App API (v2)https://api.coinbase.com/v2Indicative spot, buy and sell prices, exchange rates, and the accounts of a Coinbase app userCBAppClient
Advanced Trade API (v3)https://api.coinbase.com/api/v3/brokerageTrading on a Coinbase account: products, order book, candles, orders, fills and portfoliosCBAdvancedTradeClient
Exchange APIhttps://api.exchange.coinbase.comCoinbase Exchange (the former Coinbase Pro venue) for institutional accounts: ticker, 24 hour stats, trades and order bookCBExchangeClient

The same package also has clients for the International Exchange, Prime and Commerce APIs. For a retail Coinbase account that places orders from code, Advanced Trade is the one to build on.

Install

npm install coinbase-api

Node.js 22 or newer works for these examples. The package ships ES modules, CommonJS and TypeScript declarations.

Coinbase API market data in one script

Save this as coinbase-api.mjs. None of these calls needs an API key:

import { CBAppClient, CBAdvancedTradeClient, CBExchangeClient } from 'coinbase-api';

// Coinbase App API (api.coinbase.com/v2): indicative spot price
const app = new CBAppClient();
const { data: spot } = await app.getSpotPrice({ currencyPair: 'BTC-USD' });
console.log('app spot price:', spot.base, spot.currency, spot.amount);

// Advanced Trade API (api.coinbase.com/api/v3): product rules and last price
const advanced = new CBAdvancedTradeClient();
const product = await advanced.getPublicProduct({ product_id: 'BTC-USD' });
console.log('advanced trade:', product.product_id, 'price:', product.price, 'status:', product.status, 'base_increment:', product.base_increment, 'quote_increment:', product.quote_increment, 'quote_min_size:', product.quote_min_size);

// Advanced Trade candles: start and end are UNIX seconds, as strings
const end = Math.floor(Date.now() / 1000);
const { candles } = await advanced.getPublicProductCandles({
  product_id: 'BTC-USD',
  start: String(end - 3 * 3600),
  end: String(end),
  granularity: 'ONE_HOUR',
});
console.log('latest 1h candle:', candles[0]);

// Exchange API (api.exchange.coinbase.com): 24 hour stats and best bid/ask
const exchange = new CBExchangeClient();
const stats = await exchange.getProductStats({ product_id: 'BTC-USD' });
console.log('exchange 24h open:', stats.open, 'high:', stats.high, 'low:', stats.low, 'last:', stats.last, 'volume:', stats.volume);

const ticker = await exchange.getProductTicker({ product_id: 'BTC-USD' });
console.log('exchange ticker bid:', ticker.bid, 'ask:', ticker.ask, 'last trade:', ticker.price, ticker.time);

Run it with node coinbase-api.mjs.

Example output:

app spot price: BTC USD 52414.415
advanced trade: BTC-USD price: 52342.5 status: online base_increment: 0.00000001 quote_increment: 0.01 quote_min_size: 1
latest 1h candle: {
  start: '1796389200',
  low: '51667.37',
  high: '52686.05',
  open: '51893.39',
  close: '52360.27',
  volume: '958.32613538'
}
exchange 24h open: 52388.9 high: 55003.61 low: 50001 last: 52499.79 volume: 56921.46346865
exchange ticker bid: 52348.34 ask: 52348.35 last trade: 52348.34 2026-12-04T13:39:28.563736135Z

Prices will differ on each run.

Coinbase API response shapes and number formats

Authenticated Coinbase API calls

The private APIs sign requests in different ways, and the SDK handles each one:

Keep keys in environment variables on a server you control and give each key only the permissions it needs.

More Coinbase API examples