The Binance SDK distinguishes between two broad categories of failure: REST API errors returned by Binance’s servers with a structuredDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/binance/llms.txt
Use this file to discover all available pages before exploring further.
{code, msg} body, and lower-level network or connectivity failures that prevent a response from arriving at all. WebSocket clients introduce a third category — connection lifecycle events such as drops and reconnects — which require a different handling strategy from request/response errors. Understanding how the SDK surfaces each type, and what context it provides, lets you write recovery logic that is reliable in production.
REST API Error Structure
When Binance returns an HTTP error status (anything outside 2xx), the SDK’s internalparseException method throws a structured error object rather than the raw Axios error. That object contains everything you need to diagnose the problem:
api_key and api_secret are explicitly set to undefined in requestOptions before the error is thrown.
Basic try/catch Pattern
Wrap every REST call in a try/catch block. Accesserror.code and error.message to distinguish between error types and implement appropriate recovery:
Common Binance Error Codes
-1100 — Illegal characters in parameter
-1100 — Illegal characters in parameter
A parameter contains characters Binance does not allow. Check that string fields such as
symbol and timeInForce contain only permitted values.-1121 — Invalid symbol
-1121 — Invalid symbol
The
symbol value does not match any known trading pair. Verify the exact symbol string using client.getExchangeInfo().-1021 — Timestamp outside recvWindow
-1021 — Timestamp outside recvWindow
The request timestamp is too far from the Binance server time. Either your system clock is drifting, or
recvWindow is too tight. Enable time sync with disableTimeSync: false, or increase recvWindow.-2010 — Insufficient balance
-2010 — Insufficient balance
The account does not have enough of the required asset to fill the order. Check the account balance before placing the order.
-1013 — Filter failure
-1013 — Filter failure
The order violates a price, quantity, or notional filter defined in exchange info for that symbol. Fetch
getExchangeInfo() and validate against the returned filters before submitting.-1003 — Too many requests / rate limited
-1003 — Too many requests / rate limited
Your account or IP has exceeded Binance’s request weight limits. Inspect the
x-mbx-used-weight-1m header in error.headers and back off. Use client.getRateLimitStates() to monitor weight usage proactively.Network Errors vs API Errors
The SDK’sparseException method differentiates between three failure modes:
No request sent
Axios failed to construct the request (e.g. invalid URL). The SDK throws the raw error
message string.Request sent, no response
A request was sent but no response arrived (e.g. DNS failure, connection refused, timeout). The SDK re-throws the full Axios error object. These errors do not have a
code property from Binance — check error.request to confirm.Returning Errors Instead of Throwing
By default (parseExceptions: true), the SDK throws on every non-2xx response. Setting parseExceptions: false makes the SDK re-throw the raw Axios error instead, bypassing the structured error wrapper. This is useful only if you need to inspect the raw Axios error shape directly:
WebSocket Error Events
TheWebsocketClient is event-driven. Errors and connection lifecycle changes are emitted as named events rather than thrown. Always attach handlers before subscribing to any streams:
The
'error' event is deprecated and should not be used — it caused unhandled promise rejections when no listener was attached. Use the 'exception' event instead, which carries the same information without that side effect.Reconnection Behaviour
The SDK handles reconnection automatically — it detects silent disconnections through its heartbeat mechanism, then re-establishes the connection and resubscribes to cached topics. What the SDK does not do is backfill any market or account events that arrived while the socket was down.SDK handles automatically
Detecting silent disconnections via ping/pong heartbeat, re-establishing the connection, resubscribing to previously subscribed topics, and refreshing listen keys for user data streams.
You must handle
Reconciling account state (positions, orders, fills, balances) via REST API after a reconnect. Any events missed during the downtime will not be replayed.
Logging Errors with DefaultLogger
WhenWebsocketClient logs errors internally, it uses the DefaultLogger. You can replace it to route errors to your own monitoring stack:
The
DefaultLogger does not expose a warn method — only trace, info, and error. If your logger implementation requires a warn level, you can add it to your custom logger object without affecting the SDK’s internal calls.