← All articles

Coinbase API INVALID_SIZE_PRECISION in Node.js: increments, minimum sizes and previewOrder

Coinbase Advanced Trade rejects an order with INVALID_SIZE_PRECISION when the size has more decimal places than the product allows. Its close relatives are INVALID_PRICE_PRECISION, PREVIEW_INVALID_BASE_SIZE_TOO_SMALL and INSUFFICIENT_FUND. None of them are authentication problems: your key and JWT worked, and Coinbase read the order. The fix is to shape the order to the product’s rules before you send it.

This guide uses the open-source coinbase-api package for Node.js and TypeScript. Every snippet was type-checked against coinbase-api 1.3.2.

Why the request “succeeds” but the order doesn’t exist

Create Order often answers with HTTP 200 and success: false. The reason sits in error_response:

{
  "success": false,
  "error_response": {
    "error": "INVALID_SIZE_PRECISION",
    "message": "...",
    "error_details": "...",
    "new_order_failure_reason": "INVALID_SIZE_PRECISION"
  }
}

Coinbase marks preview_failure_reason on this object as deprecated, so read new_order_failure_reason first. In coinbase-api, submitOrder() resolves with this body rather than throwing, so always check success. Real HTTP errors (bad JWT, malformed request) are thrown as { code, message, body }.

Which code means what

Code Usual cause Fix
INVALID_SIZE_PRECISION / PREVIEW_INVALID_SIZE_PRECISION base_size is not a multiple of base_increment Round the size down to the increment
PREVIEW_INVALID_QUOTE_SIZE_PRECISION quote_size has more decimals than quote_increment Round the quote amount down
INVALID_PRICE_PRECISION / PREVIEW_INVALID_PRICE_PRECISION limit_price is off the price_increment grid Round the price to the increment
PREVIEW_INVALID_BASE_SIZE_TOO_SMALL / _TOO_LARGE Outside base_min_size / base_max_size Check both bounds after rounding
PREVIEW_INVALID_QUOTE_SIZE_TOO_SMALL Market buy below quote_min_size Raise the quote amount
INSUFFICIENT_FUND / PREVIEW_INSUFFICIENT_FUND Not enough available balance, often because open orders hold it Check available balance including fees
PREVIEW_INVALID_LIMIT_PRICE_POST_ONLY A post-only limit would cross the book and take liquidity Move the price away from the opposite side

Read the product’s rules

Every product publishes its increments and limits. getPublicProduct() needs no key:

import { CBAdvancedTradeClient } from 'coinbase-api';

const publicClient = new CBAdvancedTradeClient();
const p = await publicClient.getPublicProduct({ product_id: 'DOGE-USD' });

console.log(p.base_increment, p.base_min_size, p.base_max_size);
console.log(p.quote_increment, p.quote_min_size, p.price_increment);
console.log(p.status, p.trading_disabled, p.cancel_only, p.limit_only, p.post_only);

The values differ more than you might expect. On 25 November 2026, BTC-USD, ETH-USD and SOL-USD all used a base_increment of 0.00000001 and a price increment of 0.01. DOGE-USD used 0.1 for size and 0.00001 for price, so a size of 25.37 DOGE fails while 25.3 works. ETH-BTC priced in steps of 0.000001 with a quote_min_size of 0.00001 BTC. Read the rules at startup and refresh them now and then; don’t copy these numbers.

If you need the authenticated view (for example with tradability status), getProduct({ product_id, get_tradability_status: true }) returns the same fields.

Round with strings, not floats

The tempting fix is Math.floor(value / increment) * increment. In floating point, a price of 64123.4567 on a 0.01 grid comes out as 64123.450000000004, which is exactly the kind of value that triggers the error you were trying to avoid. Worse, 0.3 on a 0.1 grid becomes 0.2, because 0.3 / 0.1 is 2.9999999999999996. Coinbase takes sizes and prices as strings, so do the maths on integers and give a string back:

// Exact decimal maths on strings: no floating-point drift.
function toUnits(value: string, decimals: number): bigint {
  const [whole, frac = ''] = value.split('.');
  return BigInt(whole + frac.padEnd(decimals, '0').slice(0, decimals));
}

function fromUnits(units: bigint, decimals: number): string {
  const s = units.toString().padStart(decimals + 1, '0');
  const whole = s.slice(0, s.length - decimals);
  const frac = s.slice(s.length - decimals).replace(/0+$/, '');
  return frac ? `${whole}.${frac}` : whole;
}

function decimalsOf(value: string): number {
  return (value.split('.')[1] ?? '').replace(/0+$/, '').length;
}

/** Round a size or price DOWN to a multiple of the product's increment. */
export function floorToIncrement(value: string, increment: string): string {
  const d = Math.max(decimalsOf(value), decimalsOf(increment));
  const v = toUnits(value, d);
  const step = toUnits(increment, d);
  return fromUnits((v / step) * step, d);
}

export function compare(a: string, b: string): number {
  const d = Math.max(decimalsOf(a), decimalsOf(b));
  const x = toUnits(a, d);
  const y = toUnits(b, d);
  return x === y ? 0 : x > y ? 1 : -1;
}

Run against live rules, floorToIncrement('25.37', '0.1') gives 25.3 and floorToIncrement('64123.4567', '0.01') gives 64123.45. The helper expects plain decimal strings (no exponent notation), so keep sizes as strings from end to end.

Round sizes down, never up, so you never ask for more than you meant to. For a buy limit price, rounding down is also the safe direction; for a sell you may prefer to round up so the order doesn’t sit below your intended price.

Check the bounds after rounding

Rounding can push a small order under the minimum, so check limits on the rounded value, and refuse early if the product isn’t accepting orders:

export async function checkBaseSize(productId: string, wantedBase: string) {
  const p = await publicClient.getPublicProduct({ product_id: productId });

  if (p.trading_disabled || p.cancel_only || p.status !== 'online') {
    throw new Error(`${productId} is not accepting new orders (status ${p.status})`);
  }

  const base = floorToIncrement(wantedBase, p.base_increment);
  if (compare(base, p.base_min_size) < 0) {
    throw new Error(`${base} is below base_min_size ${p.base_min_size}`);
  }
  if (compare(base, p.base_max_size) > 0) {
    throw new Error(`${base} is above base_max_size ${p.base_max_size}`);
  }
  return { base, product: p };
}

With live DOGE-USD rules, asking for 0.05 DOGE rounds to 0 and fails the base_min_size check of 0.1 locally, before any order request leaves your process.

Preview, then submit with the preview_id

previewOrder() runs Coinbase’s checks without placing anything and returns a list of would-be failures in errs. It is the cheapest way to catch PREVIEW_INSUFFICIENT_FUND or a post-only price that would cross. Pass the returned preview_id to submitOrder() so the order ties back to the preview, and set your own client_order_id so a retry after a timeout can be matched to the original:

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

export async function placeLimitBuy(productId: string, wantedBase: string, wantedPrice: string) {
  const { base, product } = await checkBaseSize(productId, wantedBase);
  const limitPrice = floorToIncrement(wantedPrice, product.price_increment);

  const order_configuration = {
    limit_limit_gtc: { base_size: base, limit_price: limitPrice, post_only: true },
  };

  // 1. Preview: Coinbase lists what would fail, without placing anything.
  const preview = await client.previewOrder({
    product_id: productId,
    side: 'BUY',
    order_configuration,
  });

  if (preview.errs.length > 0) {
    // e.g. ['PREVIEW_INSUFFICIENT_FUND'] or ['PREVIEW_INVALID_LIMIT_PRICE_POST_ONLY']
    throw new Error(`Preview rejected: ${preview.errs.join(', ')}`);
  }

  // 2. Submit with the preview_id and your own client_order_id.
  const res = await client.submitOrder({
    product_id: productId,
    side: 'BUY',
    order_configuration,
    preview_id: preview.preview_id,
    client_order_id: client.generateNewOrderId(),
  });

  // 3. HTTP 200 does not mean the order exists.
  if (!res.success) {
    const e = res.error_response;
    throw new Error(
      `Order rejected: ${e?.new_order_failure_reason ?? e?.error} ${e?.message ?? ''}`,
    );
  }
  return res.success_response?.order_id;
}

If you leave out client_order_id, the SDK generates one for you. Generating it yourself, as above, means you can store it before sending and look the order up by it if the response never arrives.

The key for this needs view and trade permissions only. It never needs transfer or withdrawal access, and an IP allowlist is worth setting. See API key security best practices for the full checklist.

Market orders: base_size or quote_size

A market_market_ioc order takes either base_size or quote_size. A buy sized in the quote currency (“spend 25 USD”) is checked against quote_min_size and quote_increment, not the base rules, so round the quote amount with the same helper:

const quote = floorToIncrement('25.004', product.quote_increment); // '25'
const order_configuration = { market_market_ioc: { quote_size: quote } };

Quick checklist

  • Check success on every submitOrder() response, and read error_response.new_order_failure_reason.
  • Read base_increment, quote_increment, price_increment and the min/max sizes from getPublicProduct().
  • Round sizes down with string or integer maths, never floats.
  • Check minimums and maximums after rounding, and skip products that are disabled or cancel-only.
  • Run previewOrder() and stop if errs is not empty, then submit with preview_id and your own client_order_id.

For client setup, private WebSockets and the rest of the API, see the Coinbase JavaScript tutorial and the Coinbase SDK docs. If you trade Coinbase perpetuals, the INTX to Starbase migration guide covers the newer Global Derivatives API.