Error Handling

Understanding error codes and how to handle them gracefully.

HTTP Status Codes

CodeMeaningAction
200SuccessRequest completed successfully
400Bad RequestCheck request format and parameters
401UnauthorizedCheck API key or token
403ForbiddenSubscription expired or insufficient permissions
429Rate LimitedWait and retry with exponential backoff
500Server ErrorRetry later, contact support if persistent

Error Response Format

All error responses follow a consistent JSON format:

{
  "error": {
    "code": "INSUFFICIENT_MARGIN",
    "message": "Not enough margin to place order",
    "details": {
      "required": "1000.00",
      "available": "500.00"
    }
  }
}

Common Error Codes

INSUFFICIENT_MARGIN

Your virtual balance doesn't have enough margin for this order. Reduce position size or add funds.

INVALID_API_KEY

The API key is malformed or doesn't exist. Check for typos or generate a new key.

SUBSCRIPTION_EXPIRED

Your subscription has expired. Renew to continue using the API.

ORDER_WOULD_TRIGGER

A stop/limit order would trigger immediately. Adjust your price.

REDUCE_ONLY_VIOLATION

A reduce-only order would increase your position. Check order direction.

Debugging Tips

Log full responses

Always log the complete error response, including headers. Rate limit info is in headers.

Check request format

Ensure JSON is valid and all required fields are present. Use a JSON validator.

Verify API key scope

Make sure you're using the correct API key for the exchange you're calling.