Error Handling
Understanding error codes and how to handle them gracefully.
HTTP Status Codes
| Code | Meaning | Action |
|---|---|---|
200 | Success | Request completed successfully |
400 | Bad Request | Check request format and parameters |
401 | Unauthorized | Check API key or token |
403 | Forbidden | Subscription expired or insufficient permissions |
429 | Rate Limited | Wait and retry with exponential backoff |
500 | Server Error | Retry 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.