← All articles

Binance API error codes in JavaScript: how to read them and what to do about each one

Binance’s error code list is long, and it tells you what each code means but not what to do in your code when you hit one. This guide shows how errors arrive in Node.js with the Binance JavaScript SDK (binance on npm), then goes through the codes you’re most likely to see and how to handle each, with links to deeper fixes where they exist.

What an error looks like in the SDK

When Binance rejects a request, the SDK throws an error object that already has the Binance code pulled out, so you don’t have to parse the response yourself:

const { MainClient } = require('binance');

const client = new MainClient();

client.getOrderBook({ symbol: 'NOTACOIN' }).catch((e) => {
  console.log(e.code);       // -1121
  console.log(e.message);    // Invalid symbol.
  console.log(e.body);       // { code: -1121, msg: 'Invalid symbol.' }
  console.log(e.requestUrl); // https://api.binance.com/api/v3/depth
  console.log(e.headers['x-mbx-used-weight-1m']);
});

Besides code, message and the raw body, you get the response headers (including Binance’s used-weight counters) and the requestUrl, requestBody and requestOptions that produced the error. Log those and most problems become obvious.

Handle codes by group, not one by one

The number tells you which kind of problem you have. A small switch is usually enough:

function classifyBinanceError(e) {
  switch (e.code) {
    case -1021: // timestamp outside recvWindow
      return 'clock';
    case -1022: // signature invalid
    case -2014: // API key format invalid
    case -2015: // invalid API key, IP or permissions
      return 'auth';
    case -1003: // too many requests
    case -1015: // too many new orders
      return 'rate-limit';
    case -1100: // illegal characters in a parameter
    case -1102: // mandatory parameter missing
    case -1120: // invalid interval
    case -1121: // invalid symbol
      return 'bad-request';
    case -1013: // filter failure (price, lot size, notional)
    case -2010: // new order rejected
      return 'order-rejected';
    default:
      return 'unknown';
  }
}

Retry only what can succeed on a retry. Bad requests and auth errors will fail the same way every time, so retrying them just burns request weight.

Clock errors: -1021

-1021 means your request’s timestamp was outside the recvWindow Binance allows, usually because the machine’s clock has drifted. Fix the clock first; widening recvWindow only hides the problem. The full walkthrough is in Binance API -1021 timestamp and recvWindow errors in Node.js.

Auth errors: -1022, -2014 and -2015

  • -1022 (signature not valid): the secret is wrong, or what was signed isn’t what was sent. With the SDK signing for you, a wrong or truncated secret is the usual cause. See troubleshooting Binance API error -1022 in JavaScript.
  • -2014 (API-key format invalid): the key itself is malformed, often an empty environment variable or one with a stray space or newline.
  • -2015 (invalid API-key, IP, or permissions for action): one code for three problems, a wrong key, an IP not on the whitelist, or a missing permission. Work through them with the Binance -2015 checklist.

Rate limits: -1003 and -1015

-1003 means you’ve used too much request weight; -1015 means too many new orders. Binance reports your current usage in headers such as x-mbx-used-weight-1m on normal responses as well as errors, so you can slow down before you hit the limit rather than after. If you do get rate limited, back off: Binance escalates repeated violations into temporary IP bans, and an HTTP 429 or 418 status is the warning sign. For live data, a WebSocket stream costs no request weight at all, so moving polling loops onto streams is often the real fix. The Binance JavaScript tutorial covers the WebSocket client.

Bad requests: -1100, -1102, -1120, -1121

These all mean the request itself is wrong, and Binance’s message usually says exactly which part. A few real responses:

// getOrderBook({ symbol: 'NOTACOIN' })
// -1121 Invalid symbol.

// getOrderBook({ symbol: 'BTCUSDT', limit: 'abc' })
// -1100 Illegal characters found in parameter 'limit'; legal range is '^[0-9]{1,20}$'.

// getKlines({ symbol: 'BTCUSDT', interval: '7m' })
// -1120 Invalid interval.

If you’re writing TypeScript, the SDK’s request types catch many of these before the request is sent. -1121 is worth a special mention: a symbol that worked last month can return it after a delisting, so check the symbol against getExchangeInfo() at startup rather than hard-coding a list.

Order rejections: -1013 and -2010

-1013 is a filter failure: the price isn’t a multiple of the tick size, the quantity doesn’t match the lot size, or the order’s value is under the minimum notional. All of those rules live in the symbol’s filters from getExchangeInfo(), and rounding your price and quantity to them before sending fixes the error. See reading Binance exchange info filters for trading bots. -2010 is a general rejection of a new order, and its message carries the actual reason, such as insufficient balance, so log the message, not just the code.

Not a numbered code: 410 on user data streams

If your account stream setup suddenly fails with an HTTP 410, the old Spot listenKey flow has been retired in favour of WebSocket API user data streams, and that HTTP status isn’t one of the numbered codes at all. Binance user data stream 410 Gone in JavaScript explains what changed and how to move over.

Further reading

The Binance SDK docs list every REST and WebSocket method with its parameters, and the Binance JavaScript tutorial goes from first request to WebSocket streams and orders. The SDK is open source and part of the Siebly family of exchange SDKs, with over 4.5 million npm downloads across 10+ SDKs, and more in the works.

Disclosure: this guide is published by Siebly, the maintainers of the binance npm package.